Longest Palindrome | Leet code 409 | Theory explained + Python code

  Рет қаралды 11,972

Sai Anish Malla

Sai Anish Malla

Күн бұрын

This video is a solution to Leet code 409, Longest Palindrome. I explain the question and the best way to solve it and then solve it using Python.
Comment below if you have a better solution to this problem!
Let me know if you have any feedback and don't forget to subscribe for more videos!
Code: leetcode.com/p...)
More leetcode questions solved:
• Add and Search Word - ...
Gear used:
Mic: amzn.to/3awi3b6
Drawing pad: amzn.to/2O7PaaU

Пікірлер: 13
@FahadKhan-si7zt
@FahadKhan-si7zt Жыл бұрын
We won't need that conditional check on line 14 because our loop will handle the case where there is only 1 key value pair in our hash map.
@KhanhTran-vk5kn
@KhanhTran-vk5kn 2 жыл бұрын
Nice explanation! I also want to say that you have a pretty voice
@elezavala
@elezavala 2 жыл бұрын
loved your explanation!
@jyotijangid5243
@jyotijangid5243 4 жыл бұрын
Not related to the above question. I need to ask what is the time complexity of itertools.combinations in python when we have n, r given (constant) and combinations(array of len n, r) is executed??
@saianishmalla2646
@saianishmalla2646 4 жыл бұрын
I am not a 100 percent sure but I think it would be O(n!) with n being the length of the string.
@jyotijangid5243
@jyotijangid5243 4 жыл бұрын
@@saianishmalla2646 okay thanks
@SHIVAMKUMAR-dy7qc
@SHIVAMKUMAR-dy7qc Жыл бұрын
what is the complexity of your code? I guess it's n^2. n^2 ? "Can we reduce it more" : "great"
@dzroro
@dzroro Жыл бұрын
time complexity is O(n) , it's not a nested loop
@adeniyiadeboye3300
@adeniyiadeboye3300 2 жыл бұрын
nice explanation
@rohitkavuluru8998
@rohitkavuluru8998 7 ай бұрын
you can just combine the logic into one if/else block and use an if block outside the for loop to check if we can add one final odd character to the anagram count. count = {} for char in s: if char in count: count[char] += 1 else: count[char] = 1 length = 0 odd = False for freq in count.values(): #if the frequency is an even number, we can just add it to our total length if freq > 1 and freq % 2 == 0: length += freq else: length += freq-1 odd = True #this final case deals with the possibility of adding a singular 'odd' count to middle of the anagram. if odd: length+=1 return length this just makes more intuitive sense and the code is much cleaner.
@deepalisrivastava3477
@deepalisrivastava3477 2 жыл бұрын
Hi Anish, Thank you for explaining this solution in an easiest way. I want to mention one small thing, with the above solution, I was getting a KeyError: 'a' in line 9. But when I used 'try'-'except' in place of 'if-condition'(line 6-9) it worked for me. Thanks.
@hassanrasoolsiddiqui1325
@hassanrasoolsiddiqui1325 Жыл бұрын
Thanks for sharing this approach! The solutions available at leetcode were kinda unreadable with 3 nested loops..
@BevaraSateeshKumar
@BevaraSateeshKumar 8 ай бұрын
excellent explanation , nice taught , keep it up bro
Next Permutation | Leet code 31 | Theory explained + Python code
19:19
Sai Anish Malla
Рет қаралды 15 М.
Longest Palindrome - Leetcode 409 - Python
12:20
NeetCodeIO
Рет қаралды 13 М.
Minecraft Creeper Family is back! #minecraft #funny #memes
00:26
Шок. Никокадо Авокадо похудел на 110 кг
00:44
LeetCode 5.  Longest Palindromic Substring (Algorithm Explained)
14:40
5 Useful F-String Tricks In Python
10:02
Indently
Рет қаралды 309 М.
Leetcode 5. Longest Palindromic Substring (Python)
15:17
Pseudocoder Ravina
Рет қаралды 4,4 М.
Longest Palindrome | LeetCode 409 | C++, Java, Python
13:00
Knowledge Center
Рет қаралды 30 М.
Leetcode 5. Longest Palindromic Substring
23:52
Code with Alisha
Рет қаралды 47 М.
Minecraft Creeper Family is back! #minecraft #funny #memes
00:26