• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Programming Puzzle

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    Programming Puzzle

    Got this many years ago in an interview:

    http://digg.com/programming/Array_Re...ramming_Puzzle

    Not too hard, but hard to do in < 30 minutes under pressure.

    #2
    Completely useless waste of time to set that in an interview. If I needed to do something like that and didn't know immediately off the top of my head how to do it, I'd just Google it. Simple algorithmics are no indicator of a decent developer.

    To be honest, I'd have probably just got up and walked out. I'm a professional contractor and the only kind of tests that may be acceptable are ones directly related to the project being discussed - and even then I see them as a kind of insult.
    Listen to my last album on Spotify

    Comment


      #3
      Originally posted by Cowboy Bob
      Completely useless waste of time to set that in an interview. If I needed to do something like that and didn't know immediately off the top of my head how to do it, I'd just Google it. Simple algorithmics are no indicator of a decent developer.

      To be honest, I'd have probably just got up and walked out. I'm a professional contractor and the only kind of tests that may be acceptable are ones directly related to the project being discussed - and even then I see them as a kind of insult.
      I agree - totally useless. It was many years ago (I was still a student!) and they offered me £50 a week!

      Comment


        #4
        tulipe. Next!
        What happens in General, stays in General.
        You know what they say about assumptions!

        Comment


          #5
          As a professional business man, I'd offer the following solution.

          1. Stick the algorithm requirement on RentACoder.
          2. Pay the $10 required for the solution
          3. Bill the client £500

          HTH
          First Law of Contracting: Only the strong survive

          Comment


            #6
            don't let a certain russian see that temp var for goodness sake!

            Comment


              #7
              Maybe I'm being thick, but isn't that just a bubble sort?
              Will work inside IR35. Or for food.

              Comment


                #8
                depends how the swap function is called

                Comment


                  #9
                  Originally posted by scotspine
                  don't let a certain russian see that temp var for goodness sake!
                  too late... use assembly's command: xchg

                  Just sort the array (in place using QuickSort, supported by any good library) but use reversed key values, thus: it will sort as:

                  1a, 1b, 2a, 2b etc - of course reverse order only to be used for key comparison purposes, it won't be changed in the array: there job done in less than few minutes.

                  Of course in reality the solution should be more effective - you don't really need to swap them and trash processor cache - you need to think what you will do with the data later, say if its saving in such a state on disk then you can just do it in simple loop with counter plus fixed offset thus merging two sorted streams on the fly.

                  And if you need array with changed places for some later processing then you can do similar merging on the fly.

                  All in all stupid task that is only excusable by separating pros (who will solve it in 1 minute using existing tools) from amateurs who will actually be stupid enough to follow artificial rules instead of just bending the spoon.

                  If they don't like it then I'd walk out.
                  Last edited by AtW; 4 September 2006, 01:01.

                  Comment


                    #10
                    I obviously didn't make it clear, you are rearranging the array, not sorting it. To put it another way, you are not allowed to look at the contents of the array items to help you. So any kind of sort function is right out. Anyway who cares its old news now..! (somebody pasted a good solution on the digg page).

                    Originally posted by AtW
                    too late... use assembly's command: xchg

                    Just sort the array (in place using QuickSort, supported by any good library) but use reversed key values, thus: it will sort as:

                    1a, 1b, 2a, 2b etc - of course reverse order only to be used for key comparison purposes, it won't be changed in the array: there job done in less than few minutes.

                    Of course in reality the solution should be more effective - you don't really need to swap them and trash processor cache - you need to think what you will do with the data later, say if its saving in such a state on disk then you can just do it in simple loop with counter plus fixed offset thus merging two sorted streams on the fly.

                    And if you need array with changed places for some later processing then you can do similar merging on the fly.

                    All in all stupid task that is only excusable by separating pros (who will solve it in 1 minute using existing tools) from amateurs who will actually be stupid enough to follow artificial rules instead of just bending the spoon.

                    If they don't like it then I'd walk out.

                    Comment

                    Working...
                    X