Smallest String Starting From Leaf - Leetcode 988 - Python

  Рет қаралды 10,372

NeetCodeIO

NeetCodeIO

Күн бұрын

Пікірлер: 34
@jessicakoch2331
@jessicakoch2331 5 ай бұрын
even if I solve a problem, I immediately go to see your explanation, so many of leetcode’s editorials are indecipherable (at least for me)
@tekfoonlim4745
@tekfoonlim4745 5 ай бұрын
This is today's leetcode problem. Nice explanation man!
@raviyadav2552
@raviyadav2552 5 ай бұрын
can you make a series dedicated to trees and related concepts?
@licokr
@licokr 5 ай бұрын
Thanks for uploading the video! It motivates me. Consistency is the key! 🔑
@adityamwagh
@adityamwagh 5 ай бұрын
Hey, I think it would be a good idea to make a webextension which enables us to see this video in the leetcode tab itself!
@sathwikmadhula9527
@sathwikmadhula9527 5 ай бұрын
Neetcide, I request you to please solve the concurrency problems on leetcode. The leetcode numbers are 1114, 1115, 1116, 1117, 1188, 1195, 1226, 1242, 1279.
@vishaalkumaranandan2894
@vishaalkumaranandan2894 5 ай бұрын
That usage of min() was brilliant!!
@daikaji3833
@daikaji3833 5 ай бұрын
Today is the day. I'm tired of sitting here with this degree and being unable to use it. No more wasted potential. I am buying the 1 yr subscription right now, and I'm going all in to prepare for job hunting. Thank you for all that you do.
@MiraKumar-rm5ke
@MiraKumar-rm5ke 5 ай бұрын
I have a question, for the input - [25, 1, 3, 1, 3, 0, 2] shouldn't the output be "bbz" and not "adz" (actual output). Your input is appreciated. thanks! @NeetCodeIO
@fancypants6062
@fancypants6062 5 ай бұрын
I had to figure out the same thing as you. It is because the "lexicographically smaller" does not mean that the sum of the letters (treated as numbers) is smaller; it means alphabetic order, so anything starting with a is ahead of anything starting with b, no matter what the rest of the letters are.
@sankhadip_roy
@sankhadip_roy 5 ай бұрын
Less code but same concept class Solution: def smallestFromLeaf(self, root: Optional[TreeNode]) -> str: self.ans="{" def dfs(node, word): if not node: return word = chr(97 + node.val)+word if not node.left and not node.right: if word
@SC2Edu
@SC2Edu 5 ай бұрын
I used the same approach, it made more sense in my head.
@sankhadip_roy
@sankhadip_roy 5 ай бұрын
@@SC2Edu Yes absolutely
@MP-ny3ep
@MP-ny3ep 5 ай бұрын
Thank you so much. This was so beautifully explained.
@mohammadmohtashim7985
@mohammadmohtashim7985 5 ай бұрын
Man this is a good solution.
@yang5843
@yang5843 5 ай бұрын
I wrote mine a little differently class Solution { String rc = ""; public String smallestFromLeaf(TreeNode root) { dfs(root,""); return rc; } void dfs(TreeNode root, String temp) { if ( root == null ) return; temp = (char) ('a'+root.val)+temp; if (root.left == null && root.right == null ) { if ( rc.equals("") || temp.compareTo(rc) < 0 ) rc = temp; return; } dfs(root.left,temp); dfs(root.right,temp); } }
@og_23yg54
@og_23yg54 5 ай бұрын
dump way use E2AV way 77% faster
@rafaelhung1812
@rafaelhung1812 5 ай бұрын
thank you for your consistency
@krateskim4169
@krateskim4169 5 ай бұрын
Thank you so much
@NursultanBegaliev
@NursultanBegaliev 5 ай бұрын
Thank you! 👍👍
@chrischika7026
@chrischika7026 5 ай бұрын
im pretty sure you dont need the if not root: return part because you never have node
@PedanticAnswerSeeker
@PedanticAnswerSeeker 5 ай бұрын
table = [chr(ord('a')+i) for i in range(26)] def helper(root, nowStr): if root==None: return nowStr if root.left==None: return helper(root.right, table[root.val]+nowStr) if root.right==None: return helper(root.left, table[root.val]+nowStr) return min(helper(root.left, table[root.val]+nowStr), helper(root.right, table[root.val]+nowStr)) return helper(root, '')
@billyrobins6515
@billyrobins6515 5 ай бұрын
Nice one, good to know, that I am the first here
@chien-yuyeh9386
@chien-yuyeh9386 5 ай бұрын
🎉🎉
@dss963
@dss963 5 ай бұрын
Now tell me which is smaller in this according to the problem, "jd" or "hud"
@zweitekonto9654
@zweitekonto9654 5 ай бұрын
Greedy would work when we were reading from top down.
@3ombieautopilot
@3ombieautopilot 5 ай бұрын
The question is a little bit too easy for the Medium level.
@VinayKumar-jf3ue
@VinayKumar-jf3ue 5 ай бұрын
you're code used beat 80-90% of users
@SC2Edu
@SC2Edu 5 ай бұрын
Why not just check which string is smaller when we are at a leaf node?
@jayrathod9271
@jayrathod9271 5 ай бұрын
On the first leaf node, we don't have information about other leaf nodes
@I.II..III...IIIII.....
@I.II..III...IIIII..... 5 ай бұрын
Yeah, that's what I did. I initiated my minimumString as "", and then I just checked if minimumString == "" or currentString < minimumString then minimumString = currentString
@yusareba
@yusareba 5 ай бұрын
may I ask what highlighting/writing software?
@leeroymlg4692
@leeroymlg4692 5 ай бұрын
paint 3D
@aazzrwadrf
@aazzrwadrf 5 ай бұрын
such a bad question tbh
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 45 М.
Minimum Height Trees - Leetcode 310 - Python
23:30
NeetCodeIO
Рет қаралды 18 М.
GIANT Gummy Worm Pt.6 #shorts
00:46
Mr DegrEE
Рет қаралды 36 МЛН
How Strong is Tin Foil? 💪
00:26
Preston
Рет қаралды 84 МЛН
Как подписать? 😂 #shorts
00:10
Денис Кукояка
Рет қаралды 6 МЛН
大家都拉出了什么#小丑 #shorts
00:35
好人小丑
Рет қаралды 96 МЛН
Is Computer Science still worth it?
20:08
NeetCodeIO
Рет қаралды 181 М.
Evaluate Division - Leetcode 399 - Python
17:37
NeetCodeIO
Рет қаралды 29 М.
Microservices Gone Wrong at DoorDash
17:22
NeetCodeIO
Рет қаралды 92 М.
Longest Ideal Subsequence - Leetcode 2370 - Python
28:02
NeetCodeIO
Рет қаралды 11 М.
Programming w/o Language
1:47:00
Tsoding Daily
Рет қаралды 54 М.
AI can't cross this line and we don't know why.
24:07
Welch Labs
Рет қаралды 718 М.
Score After Flipping Matrix - Leetcode 861 - Python
22:30
NeetCodeIO
Рет қаралды 10 М.
Enter The Arena: Simplifying Memory Management (2023)
1:47:50
Ryan Fleury
Рет қаралды 39 М.
Distribute Coins in Binary Tree - Leetcode 979 - Python
17:41
NeetCodeIO
Рет қаралды 16 М.
GIANT Gummy Worm Pt.6 #shorts
00:46
Mr DegrEE
Рет қаралды 36 МЛН