hello @mansi25
a) a is array u cannot use push function on array
b) this loop will never terminate as n is never decreasing.
c) u have misunderstood the problem.
the problem says n will split into -> ( n/2, n%2 , n/2) now these new elements will again do inplace replacement
ie n/2 will again split into -> (n/2)/2 , (n/2)%2 , (n/2)/2
similarly for n%2 and it will continue untill all element reduces to 0,1
here is the solution ->
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’.