space complexity should be O(size of greatest length string) not n because we will have to store the greatest string and then we will have to return it
It's a little difficult to understand,as for the time complexity,we have one loop 0 to n-1 but for each of that we are traversing through the length of val and val keeps incrementing with each n. Space complexity will be dependent on n as we are reforming our string at each n.
Time complexity for this solution -> O(n * val.length()) = O(2 * n^2) as val.lenght
space complexity should be O(size of greatest length string)
not n because we will have to store the greatest string and then we will have to return it
this can be solved using recursion, if u want I will give u the solution that is memory optimize
hey Ashish what will be our time and space complexity for this solution ?
It's a little difficult to understand,as for the time complexity,we have one loop 0 to n-1 but for each of that we are traversing through the length of val and val keeps incrementing with each n.
Space complexity will be dependent on n as we are reforming our string at each n.
Time complexity for this solution -> O(n * val.length()) = O(2 * n^2) as val.lenght
This solution have memory limited exceeded problem for the input greater than 4
Memory limit exceeded