Not a question from the forum, which surprised me — I'd seen people on the forum say the phone screen here is basically coding rounds, IC/manager rounds, rate limiter, shopping cart, that sort of thing.
The problem was roughly a guessing-word game: given a guess word and a target word, mark the status of each position.
green: the two chars at this index are the same
yellow: the two chars at this index are different, but the guess's char at that index exists somewhere in the target
white: the two chars at this index are different, and the guess's char at that index doesn't exist in the target at all
That's how I remember the problem being stated, but the details were genuinely nasty — I had to look at the test cases he gave me and guess at the actual rule, then confirm with him:
guess: cable, target: maple -> W G W G G
guess: paple, target: maple -> W G G G G
guess: apple, target: maple -> Y W G G G
Part 1 was just: given the two words, output a string like WGWGG.
At first I just built a hashset to mark all the chars in the target, then did one for-loop scanning both words at the same time — but that failed on (apple, maple), I returned Y Y G G G. After finding the bug I switched to (1) a hashmap counting how many times each char appears in the target, (2) two passes: the first pass marks the "correct" positions, the second pass marks the "incorrect" ones. That was correct. Then into the follow-up.
The follow-up was: now we start tracking state across guesses. E.g. first guess: guess=cable, target=maple — you'll notice c and b both get marked W, right? On the second guess, if it's guess=cazle, target=maple, you should return invalid_input, because if you ran it, c and z would both come out W, but c had already appeared before (marked W on the first guess). The core idea is that a later guess word can't contain a char that was already marked W in a previous guess.
I finished both parts and got everything passing. The interviewer seemed pretty surprised I got it working... He even tried throwing in some extra test cases and it still passed, and he just had this confused look on his face lol. This was the first time I'd run into this kind of "rules problem." Honestly these are kind of nasty — they look easy but there are like eighteen thousand pitfalls waiting for you, and the interviewer won't warn you about any of them, you have to figure it all out yourself. Also his description and test cases didn't cover all the edge cases either, so I had to keep confirming with him. Overall not that easy. Probably failed it, moving on.
Discussion
Loading comments…