Lexicographical Numbers | Simple DFS | Leetcode 386 | codestorywithMIK

  Рет қаралды 8,940

codestorywithMIK

codestorywithMIK

Күн бұрын

Пікірлер: 63
@AmandeepSingh-uq3wp
@AmandeepSingh-uq3wp 2 ай бұрын
I also wrote the same code but still comes here to expand my knowledge from mik sir.
@Playvish
@Playvish 2 ай бұрын
watched the video till 6:40 and solved the question successfully
@beenasatyendrapal6405
@beenasatyendrapal6405 2 ай бұрын
exactly....
@AdarshSingh-cd8qt
@AdarshSingh-cd8qt 2 ай бұрын
Bhaii bht accha explain kiya aapne thanks
@ugcwithaddi
@ugcwithaddi 2 ай бұрын
Already done. Here to support 😊
@MohammedArmaanUddin
@MohammedArmaanUddin 2 ай бұрын
Same
@peterfromengland8663
@peterfromengland8663 2 ай бұрын
Haddi ur leetcode I'd??
@gui-codes
@gui-codes 2 ай бұрын
aaj wala easy tha bhaiya. kuch mistakes karne k baad I was able to solve.
@rockykumarverma980
@rockykumarverma980 2 ай бұрын
Thank you so much Bhaiya ji 🙏🙏🙏
@best4567
@best4567 2 ай бұрын
Another approach (using comparator) class Solution { public: vector lexicalOrder(int n) { auto lambda = [&](int &a , int &b) { string n1 = to_string(a); string n2 = to_string(b); return n2 > n1 ; }; vector nums; for(int i=1 ; i
@ckshenoy
@ckshenoy 2 ай бұрын
Even I did the same way but this takes nlogn TC. The approach suggested in the video is actually better
@bunnypubg3475
@bunnypubg3475 2 ай бұрын
Sorting nlogn lega
@aliakbaransaria3-925
@aliakbaransaria3-925 2 ай бұрын
very good explanation
@harshitgupta6554
@harshitgupta6554 2 ай бұрын
Another approach using comparator function bool cmp(int a,int b){ string s1 = to_string(a); string s2 = to_string(b); int i = 0; while(s1[i]==s2[i]){ i++; } return s1[i]
@bec_Divyansh
@bec_Divyansh 2 ай бұрын
I did this as well
@rockykumarverma980
@rockykumarverma980 2 ай бұрын
thanks for sharing this approach🙏
@harshitgupta6554
@harshitgupta6554 2 ай бұрын
@@rockykumarverma980 😇🙌
@Its_Shubham_Negi
@Its_Shubham_Negi 2 ай бұрын
This would lead to TLE since string comparision would take O(max(a,b)) for worst case
@harshitgupta6554
@harshitgupta6554 2 ай бұрын
@@Its_Shubham_Negi no u can copy this code it's running fine and string length would be 5 at max as limit of n is 10^4 so it will take O(5) in worst case eventually O(1)
@rev_krakken70
@rev_krakken70 2 ай бұрын
I tried 4 approaches 1. First used basic sorting based on string comparison 2. Next approach I used tries to implement dfs 3. 3rd one I found out that trie is not required and used bfs 4. 4th one I used iteratively.
@sourabhbindal774
@sourabhbindal774 2 ай бұрын
can you share the code of 3rd and 4th approach
@salmaniproductions1104
@salmaniproductions1104 2 ай бұрын
Thank you bhaiyya
@rishithp3077
@rishithp3077 2 ай бұрын
thank you!!
@vikramramkumar2087
@vikramramkumar2087 2 ай бұрын
Hey! Could you make a playlist for Fenwick Trees??
@abhinay.k
@abhinay.k 2 ай бұрын
thanks
@gui-codes
@gui-codes 2 ай бұрын
Bhaiya please post today's POTD - Leetcode - 440 - K-th Smallest in Lexicographical Order
@shivanshplays9218
@shivanshplays9218 2 ай бұрын
Hello MIK sir, here is the approach that I came up with, I think that this also takes the same time and space complexity, although could you please confirm? TC:O(n) SC:O(log10(n)) class Solution { public: void recur(int no, int n, vector& arr) { if (no > n) return; for (int i = no; i < no + 10 && i
@dayashankarlakhotia4943
@dayashankarlakhotia4943 2 ай бұрын
public int lexicalOrder(int n){ Listans=new ArrayList(); int cur=1; while(ans.size()
@AlexKumarI-c6d
@AlexKumarI-c6d 2 ай бұрын
bhaiya make a video on meet in the middle algorithm
@gui-codes
@gui-codes 2 ай бұрын
ye kya hai bhai ?
@AkOp-bf9vm
@AkOp-bf9vm 2 ай бұрын
I TRIED SOMETHING WEIRD INITIALLY 😂😂😂😂😂😂😂😂. THIS IS THE EXAMPLE HOW NOT TO WRITE THE CODE USING CUSTOM COMPARATOR class Solution { public: vector lexicalOrder(int n) { vector result; for(int i=1;i
@utube4026
@utube4026 2 ай бұрын
I thought the same😂😂
@dayashankarlakhotia4943
@dayashankarlakhotia4943 2 ай бұрын
Ist🎉❤
@jigarthakor3939
@jigarthakor3939 2 ай бұрын
what about iterative?
@abhishek_0513
@abhishek_0513 2 ай бұрын
Aaj wali video kis playlist mei hai ek playlist concept of recursion krke apne daali hai usme 18 videos hai usse alag bhi koi recursion playlist hai apke channel ki?
@codestorywithMIK
@codestorywithMIK 2 ай бұрын
Here is the list - I usually create two playlists for every topic : 1) Concepts Playlist - Contains from basic concepts to expert concepts. 2) Popular Interview Problems playlist. I have created concepts and interview problems playlist for 1) Graph 2) Recursion 3) DP 4) Segment Tree Planning soon to create concepts playlist for Tree as well. Graph Concepts - kzbin.info/aero/PLpIkg8OmuX-LZB9jYzbbZchk277H5CbdY&si=lZG2IJTmSW4kRrx- Graph Popular Interview Problems - kzbin.info/aero/PLpIkg8OmuX-I_49pdy1XFY6OcATnxUrrO&si=CG2JvGWVmvoSqvWA Recursion Concepts - kzbin.info/aero/PLpIkg8OmuX-IBcXsfITH5ql0Lqci1MYPM&si=614iI4NyHY-FTeJH Recursion Problems (In progress) - kzbin.info/aero/PLpIkg8OmuX-IXOgDP_YYiJFqfCFKFBDkO&si=88fBhRnr62OYTnDP DP Concepts (In progress) - kzbin.info/aero/PLpIkg8OmuX-JhFpkhgrAwZRtukO0SkwAt&si=laFVYy6ep2BkOg0s DP Popular interview problems - kzbin.info/aero/PLpIkg8OmuX-L_QqcKB5abYynQbonaNcq3&si=VHEn9b-wqTnAVyyi Segment Tree Concepts - kzbin.info/aero/PLpIkg8OmuX-K1qUIQToCllUO0UIKXt8dB&si=xm7DqRN4H0eZwna4
@abhishek_0513
@abhishek_0513 2 ай бұрын
@@codestorywithMIK thank you so much bhaiya
@manasdeora4601
@manasdeora4601 2 ай бұрын
tried implementing same solution in java, gives TLE. public class Solution { public List lexicalOrder(int n) { List ans = new ArrayList(); for (int i = 1; i n) { return; } if(ans.contains(i)) { return; } ans.add(i); for (int j = 0; j n){ return; } solve(x, n, ans); } } }
@captain-ne8qy
@captain-ne8qy 2 ай бұрын
if(ans.contains(i)) { return; } ❌❌ why this extra check? it takes O(ans.length()) each time ***************************************** for (int i = 1; i
@yashwardhansingh8401
@yashwardhansingh8401 2 ай бұрын
sir how can we done this with O(1) space
@gui-codes
@gui-codes 2 ай бұрын
space agar dekha jae to O(1) hi hai. Editorial me dekho leetcode k - Given that the maximum value for n is 50,000, the maximum number of digits d is 5. Thus, the recursion stack depth and corresponding space complexity is O(d), which simplifies to O(log 10 ​ (n)), but with a maximum constant value of 5 for practical constraints. It can also be argued as O(1).
@princeberi4501
@princeberi4501 2 ай бұрын
same code in java giving TLE.
@kancharlasrimannarayana7068
@kancharlasrimannarayana7068 2 ай бұрын
can we solve it in O(1) space conplexity?
@gui-codes
@gui-codes 2 ай бұрын
space agar dekha jae to O(1) hi hai. Editorial me dekho leetcode k - Given that the maximum value for n is 50,000, the maximum number of digits d is 5. Thus, the recursion stack depth and corresponding space complexity is O(d), which simplifies to O(log 10 ​ (n)), but with a maximum constant value of 5 for practical constraints. It can also be argued as O(1).
@kancharlasrimannarayana7068
@kancharlasrimannarayana7068 2 ай бұрын
thank you but if the constraint changes means? and if we change the question like this if we given a random array of numbers as input and asked to sort lexxigraphicak means how to do it?
@brokegod5871
@brokegod5871 2 ай бұрын
@@kancharlasrimannarayana7068 I don't quite understand what you mean but if you are saying the array has random elements and you want to sort in lexicographical order, that is nothing but the usual ascending/increasing order sorting. Lexicographically usually means according to dictionary, so yeah 1 then 2 then 3 then 4 and so on. That is just normal sorting
@kancharlasrimannarayana7068
@kancharlasrimannarayana7068 2 ай бұрын
​@@brokegod5871, [1,10,3,5,22] as input normal sort output is [1,3,5,10,22] but lexicographical sort output is [1,10,22,3,5]
@gui-codes
@gui-codes 2 ай бұрын
@@brokegod5871 right
@sujayvikramgs8588
@sujayvikramgs8588 2 ай бұрын
bhai aaj ka problem meh tho same method se solve liya tho TLE aagya time efficient nhi haina then why this T_T;
@codestorywithMIK
@codestorywithMIK 2 ай бұрын
Yes if you use array to store it will give - MLE and if you solve without using array, it will give TLE because constraint is huge. We need logarithmic approach. The video is being uploaded now ❤️🙏
@sujayvikramgs8588
@sujayvikramgs8588 2 ай бұрын
@@codestorywithMIK thanks bhaiya will watch the video now. thanks for all your efforts bhaiya :)
@dibbodas4116
@dibbodas4116 2 ай бұрын
didnt understand the space complexity
@codestorywithMIK
@codestorywithMIK 2 ай бұрын
For recursion problems, we always check what is the maximum depth of the recursion tree. If you notice , for any recursion call, you won’t go more than digits deep in recursion. Please also refer to my Recursion Concepts playlist where I have explained how to calculate space complexity of recursion calls
@dibbodas4116
@dibbodas4116 2 ай бұрын
@@codestorywithMIK bhaiya i understand the recursion tree but why it is log base 10?
@codestorywithMIK
@codestorywithMIK 2 ай бұрын
Because for any decimal number , the number of digits can be calculated by log(number) to the base 10. Let’s understand from an example : number = 234 To find the number of digits, keep dividing it by 10z 234/10 =23 23/10 =2 2/10 =0 If you notice how many times you had to divide 243 by 10 ? 3 Dividing by 10 until the number is 0 i.e. log10(number)
@dibbodas4116
@dibbodas4116 2 ай бұрын
@@codestorywithMIK thanks bhaiya now i understood
@aizad786iqbal
@aizad786iqbal 2 ай бұрын
brute force hi kar diya tha, extra space use karke :D and sorting pe, somehow it passed... class Solution { public List lexicalOrder(int n) { List ans = new ArrayList(); List list = new ArrayList(); for(int i=1; i
@prathmeshkakde3731
@prathmeshkakde3731 2 ай бұрын
from where did you learn dsa?
This Game Is Wild...
00:19
MrBeast
Рет қаралды 186 МЛН
Creative Justice at the Checkout: Bananas and Eggs Showdown #shorts
00:18
Fabiosa Best Lifehacks
Рет қаралды 8 МЛН
Lazy days…
00:24
Anwar Jibawi
Рет қаралды 6 МЛН
Lexicographical Numbers - Leetcode 386 - Python
12:44
NeetCodeIO
Рет қаралды 12 М.
LeetCode is a JOKE with This ONE WEIRD TRICK
4:54
AlgoMonster
Рет қаралды 90 М.
Lexicographical Numbers | Leetcode 386
13:18
Techdose
Рет қаралды 3,2 М.
K-th Smallest in Lexicographical Order
20:29
Techdose
Рет қаралды 1,1 М.
⚡️NEWS | RUBLE COLLAPSE | STRIKE ON CRIMEA | PUTIN IN KAZAKHSTAN
10:34
Ходорковский LIVE
Рет қаралды 168 М.
NVIDIA’s New AI: Stunning Voice Generator!
6:21
Two Minute Papers
Рет қаралды 75 М.
This Game Is Wild...
00:19
MrBeast
Рет қаралды 186 МЛН