I honestly don't remember the first two questions anymore, but they were both very easy, and it was explicitly stated that you didn't need to worry about complexity — brute force was totally fine. Even a rusty old-timer like me, who hasn't been grinding LeetCode for years, only spent 8 minutes total on those two combined.
The third question was something I'd never seen before. It's similar to Tetris, but you don't need to calculate falling pieces and there's no rotation — it's basically using Tetris pieces to fill an n×m matrix. Starting from patterns[0], you find the top-left-most cell where the piece fits and place it there, but you have to remember each shape has a different number, and the cells get filled in with whatever number corresponds to the order the piece was placed in. The input is n = 5, m = 3, patterns = [A, B, C, D, E]. The output you need to produce is:
1 2 2 2 3 3
4 . . 5 3 3
4 4 5 5 5 .
4 . . . . .
. . . . . .
There's zero algorithmic optimization involved here — you have to hand-code the array for every single Tetris shape yourself. I really tried my best, wrote over 100 lines in a desperate scramble, and in the end found out I'd mishandled one tiny boundary condition, so only one test case passed. (Such a painful lesson.)
For the fourth question I didn't pass a single hidden test case. It's a variant of something like a course scheduler problem. The input is an array like [[-2, 3], [1, 2]], where [-2, 3] means there's a light at position -2 on the number line with a range of 3, so it lights up [-5, 1] on the number line, etc. You need to find the point with the highest brightness, and among ties, the smallest index. E.g. for [[-2, 3], [1, 2]], the output is -1, because -1 is the leftmost point on the number line with brightness 2. I'm pretty sure I went out of range on the hidden test cases, because I built one giant array to store the brightness of every point on the line... According to what my prep instructor, Teacher G, said, I should have used a TreeMap instead.
Discussion
Loading comments…