I almost reached for floating-point math immediately, which would've been the wrong move.
Start by clarifying the problem constraints and edge cases, then explain the cross product formula for collinearity and outline a single-pass algorithm that builds the compressed path. Emphasize O(n) time and O(1) extra space (excluding output), and discuss handling of duplicate points and integer overflow.
Pro tip: Mention that using integer cross products avoids floating-point precision issues, and that you can optimize by writing the result in-place if the input array is mutable, reducing memory overhead.
Ask about input size, whether points are integers, if duplicate points should be removed, and if the output can be in-place. Confirm that only direction-change points, first, and last are kept.
Describe using the cross product of vectors (B-A) and (C-B). If the cross product is zero, the points are collinear; otherwise, B is a direction-change point.
Iterate through points from the second to the second-to-last, keeping a point if the cross product with its neighbors is non-zero. Always include the first and last points.
State O(n) time and O(1) extra space (or O(n) for output). Discuss in-place modification if allowed, and handling of integer overflow with larger coordinates.
Walk through a simple path (e.g., straight line, zigzag) to verify the algorithm, and mention potential pitfalls like duplicate points or all collinear points.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.