LeetCode #14: Longest Common Prefix | Vertical Scanning

preview_player
Показать описание
A step-by-step solution to #LeetCode question number 14: Longest Common Prefix
0:00 Strategy Overview
1:21 Code Walkthrough
4:22 Second Example
5:27 Third Example

#coding #programming #algorithms #tech #softwareengineer
Рекомендации по теме
Комментарии
Автор

You explained this better than the top channels on here. Thanks for your time and dedication, keep the good content coming!

EnriqueBarclay
Автор

I really appreciate you for making this video since I have gone through many other channels and could not understand the concept. You really explained it in a simple manner.Keep posting such videos because it's really helpful for beginners like me.

amrutharamesh
Автор

I'm shocked you only have 1k followers!!! You explained this problem perfectly, just subscribed!!

choclate
Автор

I've been binge watching your videos and just wanted to sincerely thank you for help. The content has been genuinely amazing.

Quick question though--why does returning base [0:0] yield "" aka an empty string? I'm not sure why I'm struggling with wrapping my head around this conceptually.

michaelrigali
Автор

One of the best explanations explained very simply

jayblur
Автор

Indeed, Neetcode’s video didn’t quite do it for me but you did. No wonder I’m subbed to this channel! Thanks for the smooth breakdown. Also, “vertical scanning” is a great way to put it, not sure how I’ve managed to never hear about it until now.

Would be cool to have a breakdown of various patterns like that. Cheers 🍻

zfarahx
Автор

Thanks for explanations, simple refactoring - if we pre-sorted strs array comparation i and len(word) is redundant becase base is shortest word

КамильМифтахов-ре
Автор

thanks for helping me with you detailed solution

RakeshRakesh-smdy
Автор

Thanks a lot for the explanation. It is really useful. I learned a lot from this.

MathanagopalS-bw
Автор

After hours of research, I finally understood it. You deserve more. Keep it up !

Goti
Автор

The best explanation line by line for all 3 cases, I got it from the first time!!!
Very well done!

thank you 🙌

Yaaaappee
Автор

Once again, best explanation out there. Thank you!

jpkeys
Автор

Thanks, the best explained on the internet

fabioful
Автор

Your explinations and diagrams are great.

But why do we need the colon after the numbers in "for word in strs[1:]"

derick
Автор

Hey love your videos, you give a great explanation. Just a question for the first example, what if for example the test case would be ["flower", "f", "flight"], a blank string is returned...

Not sure if you care or have time to look at this, but let me know what you think if you see this.

def longestCommonPrefix(strs):
if len(strs) == 0:
return ""

base = strs[0]
for i in range(len(base)):
for word in strs[1:]:
if (i == len(word) or word[i] != base[i]):
return base[0:i]
return base

longestCommonPrefix(strs=["flower", "f", "flight"])

jonathandevine