time complexity for problem 55