How would you program this?

Hmmmm. ((60 * 12) - 1) * 2 = 1438. Or something like that.

Anyway, I really like that question. Especially since it’s the hours and seconds hands. Most people think about the hours and minutes hands, so it’s really easy to just fly past that. Interesting.

Heh, actually, that’s a typo. The actual question is hours and minutes hands. It’s basically the same question either way, as it’s about realizing that both hands are moving, so you “lose” one overlap.

Although i did have one guy who was given the question, and then i left to get some coffee. When i came back, he had a huge answer, because he had calculated the total number of overlaps between any two hands, including the seconds hand, because i hadn’t been specific. He had done it correctly though.

Given the correct answer was 22, the fact that he had an answer that was so huge made me first say, “dude, wtf?” before i had realized the confusion.

No it isn’t!

  1. There are many ways to figure out “is it a multiple of N”, e.g. ((int) x / n) * n == 0 (with a few caveats)
  2. It’s fine to not know about the modulo operator, because a candidate’s immediate thought pattern should be "you know what? I don’t know how to solve this specific sub-problem, so I’m just go going make a function called is_divisible_by(n, m) whose implementation is #todo for now and call it at the appropriate place.

Programming is all about breaking down a problem. And if a candidate can’t break down fizzbuzz into it’s constituent parts and implement everything else bar the “trick” then can they really program? Sure, the optimal solution is an operator that few people use, but that’s true for the majority of programming stuff, isn’t it? It’s easy to get a “correct, but slow” solution whereas the fast one takes a lot of effort and research.

Which is why I think fizzbuzz was a decent interview question. I say was because of how famous it is now, that you get students “learning” the answer, rather than realising that solving that kind of question is a natural extension of having “learnt” to solve problems and how to program.

It’s a lot better than questions like “how many golf balls fit inside a 747” or really rubbish ones like “how many times do the hour and second hands overlap in 24 hours”! ;)

Of my initial out-of-college interviews my favourite was “he’s a blank file. Implement a linked list in whatever language (or psuedo code) you like, we’ll come back in X minutes and help you re-write it in what we use”. I finished it fast and so had to bravely leave the meeting room and go fetch them, and their first question on re-entering was “so which part of the file is your tests/tests data”… oops, didn’t think of that!

I don’t entirely disagree, but that’s a ballsy move in an interview on a prima facie simple problem.

Well, if you don’t know what modulo is, what else are you going to do? :)

Anyway, the todo can be fleshed out after the rest of the program is done, which is where you might come up with the (x/5) *5 bit, or you could ask the interviewer to give you a hint for that part, etc.

Asking them to solve it without the modulus operator is kind of more interesting anyway.

Your experiences are not unique. I’m a Database Architect/Specialist (among other things), and I approve this message.

Triggers often seem like the easy way to solve a problem, but 9/10 times, there exists a better solution that is more maintainable.

I suspect that expediency in getting a solution is often the big pressure to go with triggers. I inherited a system with database triggers that caused some surprises. Our best guess was they were added to put in a quick fix and then it became out of sight, out of mind.

  • Database triggers are evil
  • Database triggers are pure evil
  • Shit bonerz!
0 voters