re: How to lose a Job in 10 minutes VIEW POST

VIEW FULL DISCUSSION
 

Just my two cents, here, but I think the interviewers are looking to see if think about grouping the city by length first, and then check for rotation matches.

Then, if you want bonus points, I would not write a function that create the rotations for one city, but checks if two cities are rotation matches. You don't really need to creates strings, just compare offset indexes. You can quickly decide that a pair of cities are not a match here, by finding all the letter in the second city that match the first letter of the first one: if none, not a match ever, and if there are, then you just reduced the number of possible rotations "anchors".

Granted, not necessarily easy to think about all that under pressure, but that is what a whiteboard coding interview is: not focusing on the small syntax details, but on the general approach to the problem.

 

That's a nice idea. I also just thought of a useful way to check if two strings x,y are rotations of each other.

x is a rotation of y iff x occurs in yy and size(y) = 2*size(x)

Actually, it's quite similar to what you're suggesting.

code of conduct - report abuse