Leetcode Weekly Contest 339 | Find the Longest Balanced Substring of a Binary String

preview_player
Показать описание
Leetcode Weekly Contest 339 | Find the Longest Balanced Substring of a Binary String | 2 April 2023

Leetcode question no: 2609
difficulty: easy
Approach: prefix and suffix sum
optimized approach beats 90% of the test cases

Like, share and subscribe

daily leetcode challenge,
daily leetcode questions,
daily leetcode problem,
leetcode daily today,
leetcode daily problem today,
leetcode daily challenge,
leetcode daily practise,
leetcode solutions,
letcode python,
leetcode hard problems,
leetcode easy problems,
leetcode medium problems,
leetcode for begineers,
leetcode python problems,
leetcode python,
leetcode python solutions,
leetcode python hard,
leetcode python medium,
leetcode python easy,
leetcode python english,
leetcode python solutions in english

#leetcode #leet_preparation_tips #leetcodesolution #coding #interview
#CodingInterview #NovemberLeetCodingChallenge #Google #Amazon #programming #march #codinglife #meta #faang #maang
Рекомендации по теме
Комментарии
Автор

class Solution:
def findTheLongestBalancedSubstring(self, s: str) -> int:
n=len(s)
prefixZero=[0 for i in range(n)] #continous zeros ending at index i
suffixOne=[0 for i in range(n)]
for i in range(n):
if(i==0):
if(s[i]=='0'):
prefixZero[i]=1
elif(s[i]=='0'):


for i in range(n-1, -1, -1):
if(i==n-1):
if(s[i]=='1'):
suffixOne[i]=1
elif(s[i]=='1'):

print(s)
print(prefixZero)
print(suffixOne)
finalAns=0
for i in range(n-1):
finalAns=max(finalAns, min(prefixZero[i], suffixOne[i+1])*2)
return finalAns

darshankumar
visit shbcf.ru