Got a question? Feel free to drop them in the comments below! We will make sure all your queries are answered. For more insightful videos, don't forget to subscribe to our channel. Please don't turn forget to turn on the bell 🛎 notification as well! You don't want to miss out on exclusive content. Learn more about Scaler now: bit.ly/3H8NGXI
Easier version : class Solution: def maxDistToClosest(self, seats: List[int]) -> int: l = -1 ans = 0 for i in range(len(seats)): if seats[i] == 1: if l == -1: ans = i else: ans = max(ans, (i-l)//2) l = i elif i == len(seats)-1 and seats[i] == 0: ans = max(ans, i-l) return ans
Got a question? Feel free to drop them in the comments below! We will make sure all your queries are answered. For more insightful videos, don't forget to subscribe to our channel. Please don't turn forget to turn on the bell 🛎 notification as well! You don't want to miss out on exclusive content. Learn more about Scaler now: bit.ly/3H8NGXI
More leetcode problems from Trees and Graphs we need
Easier version :
class Solution:
def maxDistToClosest(self, seats: List[int]) -> int:
l = -1
ans = 0
for i in range(len(seats)):
if seats[i] == 1:
if l == -1:
ans = i
else:
ans = max(ans, (i-l)//2)
l = i
elif i == len(seats)-1 and seats[i] == 0:
ans = max(ans, i-l)
return ans
Time stamps are incorrect
What if we have more than 3 colours?
Apply count sort