Smallest String Starting From Leaf - Leetcode 988 - Python

  Рет қаралды 9,716

NeetCodeIO

NeetCodeIO

Күн бұрын

🚀 neetcode.io/ - A better way to prepare for Coding Interviews
🧑‍💼 LinkedIn: / navdeep-singh-3aaa14161
🐦 Twitter: / neetcode1
⭐ BLIND-75 PLAYLIST: • Two Sum - Leetcode 1 -...
Problem Link: leetcode.com/problems/smalles...
0:00 - Read the problem
0:08 - Drawing Explanation
5:38 - Coding Explanation
leetcode 988
#neetcode #leetcode #python

Пікірлер: 34
@jessicakoch2331
@jessicakoch2331 2 ай бұрын
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 2 ай бұрын
This is today's leetcode problem. Nice explanation man!
@raviyadav2552
@raviyadav2552 2 ай бұрын
can you make a series dedicated to trees and related concepts?
@licokr
@licokr 2 ай бұрын
Thanks for uploading the video! It motivates me. Consistency is the key! 🔑
@MP-ny3ep
@MP-ny3ep 2 ай бұрын
Thank you so much. This was so beautifully explained.
@daikaji3833
@daikaji3833 2 ай бұрын
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.
@rafaelhung1812
@rafaelhung1812 2 ай бұрын
thank you for your consistency
@user-rv1bx8hx4v
@user-rv1bx8hx4v 2 ай бұрын
Thank you! 👍👍
@vishaalkumaranandan2894
@vishaalkumaranandan2894 2 ай бұрын
That usage of min() was brilliant!!
@krateskim4169
@krateskim4169 2 ай бұрын
Thank you so much
@adityamwagh
@adityamwagh 2 ай бұрын
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 2 ай бұрын
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.
@mohammadmohtashim7985
@mohammadmohtashim7985 2 ай бұрын
Man this is a good solution.
@MiraKumar-rm5ke
@MiraKumar-rm5ke 2 ай бұрын
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 2 ай бұрын
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.
@yusareba
@yusareba 2 ай бұрын
may I ask what highlighting/writing software?
@leeroymlg4692
@leeroymlg4692 2 ай бұрын
paint 3D
@chien-yuyeh9386
@chien-yuyeh9386 2 ай бұрын
🎉🎉
@chrischika7026
@chrischika7026 2 ай бұрын
im pretty sure you dont need the if not root: return part because you never have node
@billyrobins6515
@billyrobins6515 2 ай бұрын
Nice one, good to know, that I am the first here
@sankhadip_roy
@sankhadip_roy 2 ай бұрын
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 2 ай бұрын
I used the same approach, it made more sense in my head.
@sankhadip_roy
@sankhadip_roy 2 ай бұрын
@@SC2Edu Yes absolutely
@yang5843
@yang5843 2 ай бұрын
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 2 ай бұрын
dump way use E2AV way 77% faster
@SC2Edu
@SC2Edu 2 ай бұрын
Why not just check which string is smaller when we are at a leaf node?
@jayrathod9271
@jayrathod9271 2 ай бұрын
On the first leaf node, we don't have information about other leaf nodes
@I.II..III...IIIII.....
@I.II..III...IIIII..... 2 ай бұрын
Yeah, that's what I did. I initiated my minimumString as "", and then I just checked if minimumString == "" or currentString < minimumString then minimumString = currentString
@dss963
@dss963 2 ай бұрын
Now tell me which is smaller in this according to the problem, "jd" or "hud"
@PedanticAnswerSeeker
@PedanticAnswerSeeker 2 ай бұрын
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, '')
@VinayKumar-jf3ue
@VinayKumar-jf3ue 2 ай бұрын
you're code used beat 80-90% of users
@3ombieautopilot
@3ombieautopilot 2 ай бұрын
The question is a little bit too easy for the Medium level.
@zweitekonto9654
@zweitekonto9654 2 ай бұрын
Greedy would work when we were reading from top down.
@aazzrwadrf
@aazzrwadrf 2 ай бұрын
such a bad question tbh
Reveal Cards In Increasing Order - Leetcode 950 - Python
11:14
NeetCodeIO
Рет қаралды 14 М.
Subarrays with K Different Integers - Leetcode 992 - Python
17:31
1 класс vs 11 класс  (игрушка)
00:30
БЕРТ
Рет қаралды 3,9 МЛН
Make The String Great - Leetcode 1544 - Python
10:53
NeetCodeIO
Рет қаралды 6 М.
Remove Nodes From Linked List - Leetcode 2487 - Python
13:44
NeetCodeIO
Рет қаралды 9 М.
Path with Maximum Gold - Leetcode 1219 - Python
14:53
NeetCodeIO
Рет қаралды 8 М.
Number of Students Unable to Eat Lunch - Leetcode 1700 - Python
8:22
Bitwise AND of Numbers Range - Leetcode 201 - Python
18:25
NeetCodeIO
Рет қаралды 12 М.
Score After Flipping Matrix - Leetcode 861 - Python
22:30
NeetCodeIO
Рет қаралды 9 М.
Distribute Coins in Binary Tree - Leetcode 979 - Python
17:41
NeetCodeIO
Рет қаралды 14 М.