35 ms·
Does someone else have a few programming tests on hand aside from FizzBuzz? Also InterviewStreet ( https://www.interviewstreet.com/ https://www.interviewstreet.
by codesuela 14y ago
Does someone else have a few programming tests on hand aside from FizzBuzz?
Also InterviewStreet ( https://www.interviewstreet.com/ https://www.interviewstreet.com/ ) has a nice collection of problems of varying degrees of difficulty. Quite handy if you want to "prepare" for an interview.
- gacba 14y agoThat's the beauty of FizzBuzz, you don't really need other tests. It weeds out the dead wood very quickly and when you have 10 resumes to walk through in a week, that's a handy thing. Best to know this early on to avoid wasting your time and the candidate's as well.
- eli 14y agoOther examples of FizzBuzz-level tests? They aren't exactly tough to come up with. I used to ask for a function that takes a string and returns a boolean indicating whether or not it contains all uppercase letter.
- tkahnoski 14y agoPre-Screen for us is simply provide working code that 'Finds the the four highest integers in a list of integers'. We accept any language. The controversial bit, is we ask for Big O of their solution. There are a lot of candidates who didn't get the CS degree and struggle with this, surprisingly no one has ever said "I don't know Big O". Generally, working code is enough to at least get you in the door for a face-to-face. Yet this alone filters out more than 50% of the resumes.
- deleted 14y ago[deleted]
- dpritchett 14y agoFun! Here's Ruby: def top_four_ints_from(input_list) working_set = [] input_list.each do |n| working_set.push(n) working_set.sort!.shift while working_set.count > 4 end working_set end I'm pretty sure that's O(n). Constant time to insert any one value to the working set, Roughly n sorts performed but since each individual sort covers at most five elements we're still at (5 lg 5) * n -> O(n).
- roel_v 14y agoWe deal with maps a lot, and I usually ask this one: assume a matrix. Fill the matrix with numbers, so that the outer 'ring' of numbers has the value 1, one 'ring' more to the center has the value 2, and so on. To visualize this, imagine that this matrix represents a height map, where each number represents a cell in a surface, and the value of the number is the elevation of the area of that cell. The result should be a height map of a pyramid. To make things easier, assume that the number of rows and columns in the matrix is equal, and that that number is uneven. Followup-questions may go into the direction of what if some of the assumptions are loosened, or what are the performance implications of several possible solutions, or how to do it when iterating in whatever is the most optimal manner performance-wise considering the storage implementation of the matrix (avoiding cache misses or disk seeking etc.). I've only had a single person ever pass this test, out of 10 or so interviewees. Another one was where a colleague of mine drew a car on a piece of paper and asked the candidate to explain how he would design a class hierarchy if one were to model a car in OOP. His answer was to have a class 'rectangle' and two classes 'circle' (referring to the box and the two wheels my colleague drew on the paper). Seeing the incredulous looks on our faces, he then proceeded to an unintelligible story of 'has-a' vs 'is-a' as it related to the point in the middle of the circles, and how a 'point' somehow 'was-a' circle except that it had room in the middle. True story.
- Hupo 14y ago>We deal with maps a lot, and I usually ask this one: assume a matrix. Fill the matrix with numbers, so that the outer 'ring' of numbers has the value 1, one 'ring' more to the center has the value 2, and so on. To visualize this, imagine that this matrix represents a height map, where each number represents a cell in a surface, and the value of the number is the elevation of the area of that cell. The result should be a height map of a pyramid. To make things easier, assume that the number of rows and columns in the matrix is equal, and that that number is uneven. This sounded fun, so I thought about it for a couple minutes and came up with the following in JavaScript: var pyramatrix = function(a) { a += 1 - (a & 1); // increment a by one if even var b = [], // pyramid y-axis c = a-(a>>1), // get the "center" of the pyramid (eg. 7 -> 1234321 -> 4 is the center) d = function(x) { return Math.abs((x+1)-c) }, // calculate offset from center e, f, // values for storing current index offset g = ''; // initialize string for pretty output for(var i = 0; i < a; i++) { b[i] = []; // pyramid "x-axis" (current row) for (var j = 0; j < a; j++) { e = d(i); // get y offset f = d(j); // get x offset b[i][j] = c - (e > f ? e : f); // set current index to center minus larger offset g += '['+b[i][j]+']'; // add value to pretty output } g += '\n'; // add a line break after each row } console.log(g); // print pretty output } Example usage and output: pyramatrix(7) [1][1][1][1][1][1][1] [1][2][2][2][2][2][1] [1][2][3][3][3][2][1] [1][2][3][4][3][2][1] [1][2][3][3][3][2][1] [1][2][2][2][2][2][1] [1][1][1][1][1][1][1] I was pretty satisfied when it worked exactly as intended on the first try! EDIT: Now that I look at it, you could obviously move e = d(i); outside the second for loop, but for the sake of posterity I'm not going to change the solution from what I first came up with.
- jlgreco 14y agoFind all duplicate entries in a list, with Big O.
- notaddicted 14y agoI did a phone interview once for Facebook and my interviewer used binary search of an array of integers. I think it is a good thing to use for a first filter because even if you don't know it from memory it is pretty obvious from first principles, and it involves both looping (or recursion) and branching and it is only 10 lines of code. Also there are a few twists you can apply afterwards: 1. Turn it into bisect: return the index at which the searched value should be inserted to maintain the sorted list. 2. Allow any type of array member and require a comparison function provided that returns the standard -1,0,1. 3. Point out that binary search can be used for membership testing with O(log(n)) comparisons where n is array length. Then ask for a data-structure that can perform membership testing in constant time (answer: hash table.) EDIT: the actual programming was in a shared buffer (something like etherpad). I was mock-interviewing a friend and I had him do it on paper and that worked alright too. EDIT2: The hardest part about discussing FizzBuzz is avoiding derailing the discussion into FizzBuzz code golf. #!/usr/bin/env python for i in range(1,101): print [i,"Fizz","Buzz","FizzBuzz"][(0==i%3)+2*(0==i%5)]
- ProCynic 14y ago1 line longer, but extensible. #!/usr/bin/env python rules = {3:'fizz, 5:'buzz'} for n in xrange(1, 101): print ''.join(n%x is 0 and rules[x] or '' for x in rules) or n
- Hupo 14y ago>The hardest part about discussing FizzBuzz is avoiding derailing the discussion into FizzBuzz code golf. Well, since we're going there... have some JavaScript again! for(var i=0;i++<100;console.log(((i%3?'':'Fizz')+(i%5?'':'Buzz'))||i)); In the spirit of http://140byt.es http://140byt.es I also condensed my pyramatrix function (though without the visualization) to 135 characters: function(a){a=a|1;var b=[],c=a>>1,d=Math.abs,e=0,f;for(;e<a;e++)for(b[e]=[],f=0;f<a;f++)b[e][f]=1+c-d(d(c-e)>d(c-f)?c-e:c-f);;return b} And to get the same visualization as in the original version, you can use this helper function: function(a){var b=a.length,c='',d=0,e;for(;d<b;d++){for(e=0;e<b;)c+='['+a[d][e++]+']';c+='\n'}console.log(c)} Assign those to say, pyramatrix and visualize and you can call visualize(pyramatrix(n)) and get the same pretty output!
- 14y ago