DEV Community

Discussion on: How to lose a Job in 10 minutes

Collapse
 
cathodion profile image
Dustin King

An alternative approach to this question is to put the cities into an easier to work with data structure, such as a map (aka object) of sets, with the key being a canonical rotation, and then translate that into the desired array of arrays in the output. (Here is that as a gist. )

You didn't ask for suggestions on the solution, but I couldn't resist playing around with the exercise. I might have drawn a blank if asked to come up with this at a whiteboard though. My first solution was four nested loops.

Collapse
 
albinotonnina profile image
Albino Tonnina

Hi Dustin, thanks for your reply!
I didn't ask for suggestion because I'm sure there are so many solutions to this test!
More performant, more declarative, more functional, more more more :)
Someone may even find an O(1) version of this, I don't know :D

As you said the problem is doing it there, under pressure. I like to write elegant code, I like approaching problem methodically, I do like these problems. But my method it just doesn't work in a context like that. Not when the stakes were so high.

Collapse
 
rafegoldberg profile image
Rafe Goldberg

@poof – speak truth my man!

Collapse
 
tillg profile image
Till Gartner

I do whiteboard interviews (interviewers side ;) ).
A clean and readable solution with nested loops would have been perfect for me.

Collapse
 
ope profile image
Ope Adeyomoye

I laughed so hard at "four nested loops" 😂😂😂