Dynamic Programming21 sections · 916 units
Open in Course

Implementation Tips

Practical advice

Tip 1: Handle edge cases. Empty deque, single line, parallel lines (same slope). Check before accessing deque elements. Tip 2: Use exact arithmetic for intersection comparisons. Avoid floating point. Cross-multiply instead of dividing. Tip 3: For debugging, print the hull after each insertion. Verify that intersection x-coordinates are increasing. Tip 4: Template your CHT. Once debugged, reuse. The logic is tricky to get right from scratch under time pressure.

Time complexity: O(n)O(n) amortized for inserting nn lines.

Space complexity: O(n)O(n) for storing lines in the deque.