Two Sigma OA, bombed the tree one
Two Sigma OA, bombed the tree one
Took the Two Sigma SWE OA on Sunday, 2 questions. I'm pretty sure I'm out, so writing this down while it's still fresh.
First one was fine. Second was Pythagorean Triples, and I'd never seen it before. You get a tree as two edge arrays, plus three distinct nodes x, y, z. For every node in the tree you look at its distance to each of those three, sort them, and check if they make a right triangle. Count how many nodes pass.
Once I stopped panicking it's really just three BFS passes from x, y and z, then a loop over nodes. My first attempt ran a BFS per node, which is n squared, and I didn't catch that until a couple of hidden tests timed out. Rewrote it with maybe 12 minutes left and I'm still not sure the rewrite passed everything.
I also tripped over a test where the target nodes sat right next to each other on a long chain. Kept trying to reason about 0 distance cases and wasted time.
Has anyone heard back from Two Sigma after a partial OA? Recruiter said 1 to 2 weeks.