3 ms·
That kind of math is fine. The mod operator is not one that everyone uses but add/sub/mul/div is something most people use all the time. It is why I avoid mod
by sumtechguy 6y ago
That kind of math is fine. The mod operator is not one that everyone uses but add/sub/mul/div is something most people use all the time. It is why I avoid mod in that situation.
Once I show someone the 'mod' trick they instantly get it (if they have any sort of math background) but I want to avoid as much as possible anything tricky in a interview. I want them relaxed and not tense. As that is a different kind of test. Throwing in a trivia trick can hurt the interview. I have run across many programmers that are decent at it and have never used it.
Also for your problem it would depend on the level you are interviewing for and how much time you want to allocate for it. As it is also a balance of filter and getting to know them which is mostly time management on your part. Remember you probably are going to be working with them. So a bit of chit chat goes a long way too. You can also use 'fizzbuzz' as a question 'do you know the trick of fizzbuzz'. If I show them the mod trick and they get it right away they show aptitude to learn. If they already know it then see if they can explain it. etc etc... Get them to talk. Also talk back to them like a peer as they very well could be! They should be interviewing you too.
I just try to avoid tricky bits in interviews and expecting tricky results from them. It would be like asking the to write a swap two values function and expecting the triple xor solution. Tricky is for something you have been working on for 3 weeks and need a better solution, plus two spike stories. It is not for interviews. :) Just ask yourself would you be massively annoyed if someone asked you this in an interview with no context as to why and expected a particular answer. If the answer is you would be annoyed then do not do it. If you feel it is OK and you would expect it then go for it. Just remember your time management.
- tsukikage 6y agoI mean, "is x divisible by y?" is only one aspect of fizzbuzz, and something that can be solved in many ways - you don't have to use the mod trick. You could write a function that uses a loop and subtraction to do that bit, if it comes down to it. If I just want to see you can code I'll take it and move on, and if I'm at a point in the interview where I am looking for something else then that's a conversation starter. But if you are applying for a programming position and claim a decade of programming experience - and literally can't come up with any path towards a solution - I smell a rat.
- sumtechguy 6y agothats fair