3 ms·
Also often the puzzles have very little to do with your coding skills and everything to do with knowing some mathematical trick. Don’t know if it’s still the ca
by silveroriole 7y ago
Also often the puzzles have very little to do with your coding skills and everything to do with knowing some mathematical trick. Don’t know if it’s still the case but when I was in uni everyone told you to do Project Euler to prepare for interviews/learn coding. God help the people who had that as one of their first encounters with programming, I would have been turned off it for life!
- TeMPOraL 7y agoExactly. Now to be honest, over the years I've learned to appreciate the power multiplier deep math knowledge is, but that's not what interested me in programming. And most of the time, it's also not what's useful in a job context.
- 0x445442 7y ago> Also often the puzzles have very little to do with your coding skills and everything to do with knowing some mathematical trick Yeah, my favorite "puzzle" that highlights the folly of such things is this; write a function which, given the number of participants (n), returns the number of games/matches necessary to be played in a single elimination tournament to determine a winner. I actually asked this question in an interview once, only I was the interviewee. I had just fumbled about with all the nonsense algorithm problems that had no relevance for the job when the interviewer asked if I had any questions. I popped that one on him and to my surprise he actually took up the challenge. But since he didn't know the trick he fumbled about on some recursive goose chase.
- barbecue_sauce 7y agoI don't even know what a single elimination tournament is.
- schoen 7y agoIt's a tournament where the loser of each match is immediately eliminated from the tournament. Normally with a tree-structured bracket, or as nearly as possible.
- sirsar 7y agoThis doesn't sound much like a trick[0] question to me, it just takes working out a few examples by hand to guess that it's `n-1`, and the proof isn't hard either. And the result shouldn't be surprising: if sorting can be done in O(n log n) comparisons, it should be easier than `n log n` to just find the maximum/minimum element. Even without doing any math, or proofs, or having any algorithmic background, it shouldn't take "fumbling about on some recursive goose chase" to write the function from first principles: >>> def games(players): ... if players <= 1: return 0 ... if players == 2: return 1 ... return 1 + 2 * games(players // 2) ... >>> games(8) 7 If your interviewer couldn't come up with that, I wonder how well they do with real-world recursive algorithms on the job. It bears some resemblance to real-world problems I've had: groups of IPs combining into groups-of-groups-of-groups for addressing, computing permissions for teams-of-teams on the org chart, etc. [0] To me, trick questions involve some hard-to-come-by "aha" moment, like the XOR trick to swap two variables without a temp. This one doesn't seem to have that.
- 0x445442 7y agoIt's even easier than that... return players - 1. The trick is knowing in any single elimination tournament in order for there to be one winner there must be n - 1 losers. edit: Also, I'm not sure your solution works for 13 players.
- sirsar 7y agoI wrote that it was `n-1` in my comment. Doesn't seem like much of a trick to me.
- saalweachter 7y agoA cognitive psychologist I worked with referred to these as insight problems. You need to have one critical piece of insight to solve the problem, and then it's done. If you have the insight, you solve it, if you don't, you don't. He was constantly bemoaning how much of the research into human thinking revolved around insight problems, which you can give each subject once and at best time how long it takes for the insight to occur, instead of repeatable cognitive tasks that you could give the same subjects over and over while varying different parameters, to draw richer conclusions from.