I also wrote the same code but still comes here to expand my knowledge from mik sir.
@Playvish2 ай бұрын
watched the video till 6:40 and solved the question successfully
@beenasatyendrapal64052 ай бұрын
exactly....
@AdarshSingh-cd8qt2 ай бұрын
Bhaii bht accha explain kiya aapne thanks
@ugcwithaddi2 ай бұрын
Already done. Here to support 😊
@MohammedArmaanUddin2 ай бұрын
Same
@peterfromengland86632 ай бұрын
Haddi ur leetcode I'd??
@gui-codes2 ай бұрын
aaj wala easy tha bhaiya. kuch mistakes karne k baad I was able to solve.
@rockykumarverma9802 ай бұрын
Thank you so much Bhaiya ji 🙏🙏🙏
@best45672 ай бұрын
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
@ckshenoy2 ай бұрын
Even I did the same way but this takes nlogn TC. The approach suggested in the video is actually better
@bunnypubg34752 ай бұрын
Sorting nlogn lega
@aliakbaransaria3-9252 ай бұрын
very good explanation
@harshitgupta65542 ай бұрын
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_Divyansh2 ай бұрын
I did this as well
@rockykumarverma9802 ай бұрын
thanks for sharing this approach🙏
@harshitgupta65542 ай бұрын
@@rockykumarverma980 😇🙌
@Its_Shubham_Negi2 ай бұрын
This would lead to TLE since string comparision would take O(max(a,b)) for worst case
@harshitgupta65542 ай бұрын
@@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_krakken702 ай бұрын
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.
@sourabhbindal7742 ай бұрын
can you share the code of 3rd and 4th approach
@salmaniproductions11042 ай бұрын
Thank you bhaiyya
@rishithp30772 ай бұрын
thank you!!
@vikramramkumar20872 ай бұрын
Hey! Could you make a playlist for Fenwick Trees??
@abhinay.k2 ай бұрын
thanks
@gui-codes2 ай бұрын
Bhaiya please post today's POTD - Leetcode - 440 - K-th Smallest in Lexicographical Order
@shivanshplays92182 ай бұрын
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
@dayashankarlakhotia49432 ай бұрын
public int lexicalOrder(int n){ Listans=new ArrayList(); int cur=1; while(ans.size()
@AlexKumarI-c6d2 ай бұрын
bhaiya make a video on meet in the middle algorithm
@gui-codes2 ай бұрын
ye kya hai bhai ?
@AkOp-bf9vm2 ай бұрын
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
@utube40262 ай бұрын
I thought the same😂😂
@dayashankarlakhotia49432 ай бұрын
Ist🎉❤
@jigarthakor39392 ай бұрын
what about iterative?
@abhishek_05132 ай бұрын
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?
@codestorywithMIK2 ай бұрын
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_05132 ай бұрын
@@codestorywithMIK thank you so much bhaiya
@manasdeora46012 ай бұрын
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-ne8qy2 ай бұрын
if(ans.contains(i)) { return; } ❌❌ why this extra check? it takes O(ans.length()) each time ***************************************** for (int i = 1; i
@yashwardhansingh84012 ай бұрын
sir how can we done this with O(1) space
@gui-codes2 ай бұрын
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).
@princeberi45012 ай бұрын
same code in java giving TLE.
@kancharlasrimannarayana70682 ай бұрын
can we solve it in O(1) space conplexity?
@gui-codes2 ай бұрын
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).
@kancharlasrimannarayana70682 ай бұрын
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?
@brokegod58712 ай бұрын
@@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
@kancharlasrimannarayana70682 ай бұрын
@@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-codes2 ай бұрын
@@brokegod5871 right
@sujayvikramgs85882 ай бұрын
bhai aaj ka problem meh tho same method se solve liya tho TLE aagya time efficient nhi haina then why this T_T;
@codestorywithMIK2 ай бұрын
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 ❤️🙏
@sujayvikramgs85882 ай бұрын
@@codestorywithMIK thanks bhaiya will watch the video now. thanks for all your efforts bhaiya :)
@dibbodas41162 ай бұрын
didnt understand the space complexity
@codestorywithMIK2 ай бұрын
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
@dibbodas41162 ай бұрын
@@codestorywithMIK bhaiya i understand the recursion tree but why it is log base 10?
@codestorywithMIK2 ай бұрын
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)
@dibbodas41162 ай бұрын
@@codestorywithMIK thanks bhaiya now i understood
@aizad786iqbal2 ай бұрын
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