One algorithm question, one project question, an AI-coding debug round.
Q1: There are infinitely many bags in a row. Each segment [l, r, v] means bags l through r each hold v dollars. Segments do not overlap, and empty bags count as 0. Pick k consecutive bags and find the maximum total amount, mod 1e9+7. Constraints: n <= 2e5, and k and the coordinates go up to 1e9. Similar to LC 3413.
Example: k=5, segments = [[1,4,2],[6,6,5],[7,7,7],[9,10,1]], the answer is 16.
Q2: A Node backend for a car rental app with three bugs: other people's cars show up in My Cars, a newly added car doesn't appear, and an edit is lost after refresh. Fix them until the preset tests all pass.
Work Simulation: one screen is a project that hasn't started yet, where you score possible next actions; the other screen is scoring 5 different vote storage approaches.
[What it tests]
In Q1 the coordinates go up to 1e9, so you can't brute-force every bag, you need coordinate compression. After compression it's a prefix sum or a sliding window, but the window may cover only half of a segment, and when you subtract the partial segment's value you have to be careful with operator precedence in the multiplication. Q2 tests how fast you can read someone else's code and find bugs; the three bugs are independent of each other.
[Direction for the solution]
Q1: First collect all segment endpoints and sort them to do coordinate compression, then run prefix sum + binary search on the compressed coordinates, or a two-pointer sliding window. The key is handling the case where the window's start or end lands in the middle of a segment, so you only take part of that segment. Q2: Go function by function against the API docs and check the filter conditions, the insert logic, and whether updates are actually persisted.
I finished both coding questions plus the debugging in a bit over twenty minutes in total.
Discussion
Loading comments…