Naive solution O(n^2)- Timeout on some TestCases
O(n) Solution - Passed all Test Cases