It could be done in linear time complexity using recursion

I can’t upload the solution. Using recursion the solution is O(n).

Its giving stackoverflow in that

Click here to start solving coding interview questions