Hi guys!
i'm in the process of looking for a job and in interviews i get asked a bunch of algorithm and programming riddles, so i decided to make a thread just for lolz.
i will update it with riddles from time to time.
Riddle 1: there is an Array of 99 cells, and in it the integers from 1 to 100 but one is missing.
(the first index of a cell in the array is 0).
describe the most efficient way of finding the missing number if:
a) the array is sorted in ascending order.
b) if the array is not sorted.
easy, eh? lets try another one.
Riddle 2: there is an Array of 1's and 0's of length n. can you sort the array IN PLACE, with all the 0's on one side and all the 1's on the other side while only reading each cell in the array ONCE? (this riddle simulates a very memory constrained situation)
i.e. 0110101001 => 0000011111 (n can be either odd or even)
still easy? check this out:
Riddle 3: describe a data structure which represents an array of length n that can be initialized to a specific value K in a fixed number of operations (meaning O(1), not the order of the length of the array which would be O(n) ). this class must also implement Set(index,value) in O(1) and Get(index) in O(1).
these are not "homework questions", those are some of the easier questions that pop up in interviews from time to time, but frankly IMO have no place when interviewing a skilled programmer with several years of experience...these can be useful when interviewing graduates with no professional experience. </rant>
have fun!
P.S if you already know the answer and no one has posted it use spoiler tags. let the people think for themselves.
i'm in the process of looking for a job and in interviews i get asked a bunch of algorithm and programming riddles, so i decided to make a thread just for lolz.
i will update it with riddles from time to time.
Riddle 1: there is an Array of 99 cells, and in it the integers from 1 to 100 but one is missing.
(the first index of a cell in the array is 0).
describe the most efficient way of finding the missing number if:
a) the array is sorted in ascending order.
b) if the array is not sorted.
easy, eh? lets try another one.
Riddle 2: there is an Array of 1's and 0's of length n. can you sort the array IN PLACE, with all the 0's on one side and all the 1's on the other side while only reading each cell in the array ONCE? (this riddle simulates a very memory constrained situation)
i.e. 0110101001 => 0000011111 (n can be either odd or even)
still easy? check this out:
Riddle 3: describe a data structure which represents an array of length n that can be initialized to a specific value K in a fixed number of operations (meaning O(1), not the order of the length of the array which would be O(n) ). this class must also implement Set(index,value) in O(1) and Get(index) in O(1).
these are not "homework questions", those are some of the easier questions that pop up in interviews from time to time, but frankly IMO have no place when interviewing a skilled programmer with several years of experience...these can be useful when interviewing graduates with no professional experience. </rant>
have fun!
P.S if you already know the answer and no one has posted it use spoiler tags. let the people think for themselves.
Last edited: