KCG Interview Question

- SQL query - implementing algorithm with O(n) complexity