Largest Substring Between Two Equal Characters - Leetcode 1624 - Python

preview_player
Показать описание


0:00 - Read the problem
0:12 - Drawing Explanation
4:43 - Coding Explanation

leetcode 1624

#neetcode #leetcode #python
Рекомендации по теме
Комментарии
Автор

Just finished this question by myself then hopped on YouTube and saw that you posted the solution to it. It was an easy question but really glad I was able to conceptualize the problem and figure out a solution similar to yours within 5 minutes. Your tutorials has elevated my problem solving skills better than any professor I've ever had. Thank you.

KevHnh
Автор

Good way to end the year with a leetcode daily problem ! Happy New Year NeetCode aka Navdeep !!!

VidyaBhandary
Автор

2:47
"we need to know at what index did we C the C"
NeetQuote 😁

omaryahia
Автор

5:32 Another benefit to using `enumerate` over `range` is that you don't have to worry about remembering whether to subtract 1 or not, since enumerate just enumerates over every element.

hamirmahal
Автор

Leet code time consuming data is still confusing. Sometimes it's less and other times it's more for the same code.

Do you have a big O notation video to understand this ?
Thanks!

yashsolanki
Автор

Why don’t we just a two pointer helper method ?

def first_and_last(s, ch):
l = 0
r = len(s)-1

while l <= r:

if s[l] == s[r]:
return (r-l)-1

if s[l] != ch:
l += 1
if s[r] != ch:
r -= 1

Now call the above method for the string and all the distinct characters


char_set = set()

best_len = -1

for i in s:
char_set.add(i)

for ch in char_set:
tmp = first_and_last(s, ch)
best_len = max(best_len, tmp)

return best_len

sach
join shbcf.ru