Find the farthest element from 1 which is a zero

Given a set of inputs consisting of only 0’s and 1’s find the farthest 0 from a 1.
Example1 : 1 0 0 0
Answer1 : 3 ( 4 - 1) The indices
Example2 : 1 0 0 1
Answer2 : 2

My Approach:

li = list(map(int,input().split()))
left = 0 
right = len(li)
while(li[left]==1 and li[right-1]==1):
    right -= 1
lefttoright = right-left-1
left = 0
right = len(li)
while(li[right-1]==1 and li[left]==1):
    left += 1
righttoleft = right-left-1

print(max(lefttoright,righttoleft))

Any idea how to solve this?

You can check this code

@dontcheckme Any idea why my approach is failing? I am moving left to right and right to left greedily every time and eventually finding the max of all the distances.

You are not taking the cases where 0 can be either side of 1 .You are only checking in direction at a time greedly.