brute forced prob4 in O(n^2)
added stack complexity to prob 1 and 2