Simple Enough (WA)

I’m getting wrong answer on last test cases. Please suggest any other method for this problem.

Look at the constraints, you are making 3 recusive calls , so you complexity reaches 3 raise to power number of levels or O(3^n).
It is easy to see that the total number of elements in the final list will be 2logn + 1. The problem can be solved by locating each element in the list and checking whether it is ‘1’ .The ith element can be located in O(logn) by using Divide and Conquer strategy. Answer is the total number of all such elements which equal ‘1’.
You can see the implementation here.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.