Word break problem — fastest algorithm with javascript on leetcode

preview_player
Показать описание
I had solved this problem with O( L* (n + D) ) complexity, where
L - the maximum length of the dictionary word
D - count of words in the dictionary
n - length of string to break

While "fastest" solution on leetcode provide O( N^2 * D * L )

So I'll show why it is so and explain how it works.

Learn how to solve problems and design an algorithm from scratch with javascript.
1. Welcome (00:00)
1. Understand the problem (1:09)
2. Design an algorithm (4:00)
3. Optimize (19:40)
4. Code (27:07)
6. Benchmark! (35:35)
7. Be proud of yourself! (43:09)

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

What if I want the output to be an array of the broken words, not booleans. Any ideas how to do that? How do you deal with words that can also be part of other words?

EricTirado
Автор

What editor are you using? It isn't leetcode, but you have submit and test options. Some kind of VS code plugin?

amir_vr
Автор

Do you check algorithm complexity by yourself before use, or just copy-paste it from somewhere? :-)

AlexZAV
visit shbcf.ru