Quant Memo
Coding/●●●●●

Compact a sorted price ladder in place

A price ladder arrives as a sorted (non-decreasing) list, but some levels repeat. Overwrite the array in place so the first part holds each distinct price once, in order, and return how many distinct prices there are. Elements past that length may hold anything.

prices = [10, 10, 11, 12, 12]
-> 3   with prices[:3] == [10, 11, 12]

Compact the sorted array in place and return the count of distinct values. Aim for O(n)O(n) time, O(1)O(1) space.

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions