can this have a better solution than the naive O(n*log(n)) approach. if yes can you please suggest an approach : you are given a string consisting of only 1's. eg: "11111111"
you have an iterator that changes direction when it hits the extremes of the string. starting in the direction left to right.
the iterator replaces the next immediate '1' in its path with a zero and then skips to the '1' following that. This goes on until there is only one '1' remaining in the string.
you have to print the location of that '1'.

here is a python 3 code with the naive solution (it also prints the steps for understanding the problem, although steps are not required for the expected answer):

    n=int(input("enter the number of people in the row : "))
    assert(n>=1)
    input_string="1"*n
    print(input_string)
    direction=1
    iterator=0
    count=0
    while(count!=1):
      count=0
      next_to_delete=-1
      while(iterator<len(input_string) and iterator>=0):
        if(input_string[iterator]=='1'):
          if(next_to_delete==-1):
            next_to_delete=iterator
          else:
            input_string=input_string[:iterator]+"0"+input_string[iterator+1:]
            #i.e. input_string[iterator]='0'
            next_to_delete=-1
          count+=1
        iterator+=direction
      print(input_string)
      direction=1 if direction==-1 else -1
      iterator+=direction
    print("answer is : ",end='')
    print(next_to_delete+1)