IGT interview question

algorithmic question about O(n) complexity