Largest number formed from an array

  Рет қаралды 124,520

Techdose

Techdose

Күн бұрын

Пікірлер: 233
@shivatomar4319
@shivatomar4319 4 жыл бұрын
This is only channel which talk about the intuition of the approach like he actually tells why we doing everything ! Great work man. Keep up the good work, please keeping bringing more questions like this if possible more frequently...we enjoy solving problems with you.
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :) I will try my best to keep it as frequent as possible.
@faizanhassan2088
@faizanhassan2088 4 жыл бұрын
@@techdose4u He is absolutely right, Sir.
@nikhilkumarjamwal5322
@nikhilkumarjamwal5322 Жыл бұрын
​@@techdose4u O(n^2)? Can you explain how it is O(n)?
@akshatjain6854
@akshatjain6854 4 жыл бұрын
Brother I have been watching your videos and I am in love with coding just coz of u. Thank you so much bro. Keep uploading these type of videos. Coding community needs u.
@jiteshkumar3112
@jiteshkumar3112 4 жыл бұрын
best channel who's main motive is to tell approach and clear the concept..thanks you Sir!
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@jiteshkumar3112
@jiteshkumar3112 4 жыл бұрын
@@techdose4u sir can you please upload some concepts and questions of backtracking. i tried alot but able to grab it in while solving dp and resursion problem
@HariKrishnan-ff4hf
@HariKrishnan-ff4hf 4 жыл бұрын
Thanks for doing the inner explanation of Comparator..i was unhappy about geeksforgeeks explanation..but you cleared it👍
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@anilchaudhry804
@anilchaudhry804 4 жыл бұрын
Exactly
@deepikadhamija4548
@deepikadhamija4548 4 жыл бұрын
They way u explain things , clear all the doubts. Thnx for making such explanatory videos
@techdose4u
@techdose4u 4 жыл бұрын
Welcome
@blazedcosmicgoat5226
@blazedcosmicgoat5226 3 жыл бұрын
for those saying it's O(N2) just implement the same logic in mergesort inside the merge function and you will have nlogn complexity.
@mobilesuniverse
@mobilesuniverse 2 жыл бұрын
yeh sabse best video hai, bhaut jagah solution deka , samaj ni aya, vector hashmap use kar rhe the
@alokesh985
@alokesh985 4 жыл бұрын
Excellent video. Couldn't find a better explanation online!
@techdose4u
@techdose4u 4 жыл бұрын
Welcome
@cseengineering8582
@cseengineering8582 2 жыл бұрын
your voice and explanation both are so clear, this thing attracts me to this channel.
@ShreyaSingh-vr9qi
@ShreyaSingh-vr9qi 4 жыл бұрын
Video is good, but you used selection sort technique. So, time complexity is O(n^2). Thanks for making video bro, I am currently in my pre-final year preparing for product based companies. Whenever i stuck on a problem or not get good expaination from GFG. in 70./. of cases i got your tutorial which helps me. Thanks again for your hard work.
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :) The time complexity will be O(NlogN) because you will use Merge sort. I just chose it for simplicity.
@vaibhavjain79
@vaibhavjain79 2 жыл бұрын
Hello. I am a pre final year student now and by reading your comment I interpret that you have completed your graduation by now.. Didi can you please tell me which product based you were trying for and which company you are currently in and your preparation strategy.. I will be really helpful if you reply to me and help me by your guidance
@akshayapanda2342
@akshayapanda2342 2 жыл бұрын
Please don't provide wrong information, Do you think the sorting technique you have used here will give nlogn time complexity?
@RIPNANI
@RIPNANI 3 ай бұрын
N*N😢
@blume0f
@blume0f 4 жыл бұрын
sir i have huge respect for u... if i land a job i will love to meet and thank u a dozen... and dont stop making videos until u hit a million!
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@Thorfin12346
@Thorfin12346 4 жыл бұрын
its O(n^2)
@naresh45544
@naresh45544 3 жыл бұрын
Exactly. This is basically selection sort with the special comparison.
@saitejaballa6759
@saitejaballa6759 3 жыл бұрын
Using merge sort with custom sort operation is O(nlogn)
@varunnarayanan8720
@varunnarayanan8720 4 жыл бұрын
Some kind of Bubble sort is used here but the logic is explained which is the most important part. Very good video
@robertsedgewick1266
@robertsedgewick1266 3 жыл бұрын
Very clear explanation. Makes the solution so intuitive!
@techdose4u
@techdose4u 3 жыл бұрын
Thanks :)
@rhythmbhandari8549
@rhythmbhandari8549 3 жыл бұрын
The explanation is pretty much simple and easy Thank you
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@rohittopal1498
@rohittopal1498 4 жыл бұрын
wooow , When i read question It seems very hard after I watched this video . It is very easy for me
@davidjonson303
@davidjonson303 Жыл бұрын
Thanks sir ..for such video Your video is so easy to understand and help us a lot
@CodeSuccessChronicle
@CodeSuccessChronicle 3 жыл бұрын
You’re my motivation to start coding.... thank you so much please keep inspiring us with your intuition.....
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@dineshs2484
@dineshs2484 9 ай бұрын
This technique will surely take o(n*2) as there is two loops comparing the eeach elements.but the solution was easy to understand.
@mausham5449
@mausham5449 4 жыл бұрын
u really explain very well.thanks. plz keep posting regularly.
@techdose4u
@techdose4u 4 жыл бұрын
Thanks....sure I am posting regularly.
@ihopethiscommentisntabusiv4670
@ihopethiscommentisntabusiv4670 3 жыл бұрын
Thank you for the video, but as someone mentioned the runtime is O(N^2), would be help to add the disclaimer that this can be done with mergesort to get N log(N). Either way thanks!
@techdose4u
@techdose4u 3 жыл бұрын
:)
@akashpradipj
@akashpradipj 2 жыл бұрын
@@techdose4u in case of merge sort, how you are going to include the comparison of two strings based on their integer representation?
@goutamkundu6392
@goutamkundu6392 3 жыл бұрын
Great explanation Surya. Really liking your channel. Respect from your past colleague.
@techdose4u
@techdose4u 3 жыл бұрын
Thanks Goutam ❤️
@techacemidhun
@techacemidhun 4 жыл бұрын
// Implementation of the logic class Solution{ public: // Merge two numbers string numberMerge(int a, int b){ string s1 = to_string(a); string s2 = to_string(b); return s1 + s2; } // Compare given two strings and decide they needed to be swapped. bool compareStrings( string s1, string s2 ){ if(s1 < s2){ return true; // need interchange }else{ return false; // no need to interchange } } // Core logic of the program string coreLogic(vector nums){ // Variables string largeNumber; int len = nums.size(); int temp; // Loop for(int i = 0 ; i < len ; i++){ for(int j = i+1; j < len ; j++){ string s1 = numberMerge(nums[i], nums[j]); string s2 = numberMerge(nums[j], nums[i]); if(compareStrings(s1, s2) == true){ // Swapping the numbers temp = nums[i]; nums[i] = nums[j]; nums[j] = temp; } } } // Return for(int i = 0 ; i < len ; i++){ largeNumber.append( to_string(nums[i]) ); } return largeNumber; } };
@varsha9094
@varsha9094 4 жыл бұрын
is this c++?
@ryanaugustine5940
@ryanaugustine5940 2 жыл бұрын
public static Integer getLargestNumberFromArray(int[] input) { PriorityQueue t = new PriorityQueue(Collections.reverseOrder()); for (int a : input) { t.add(Integer.toString(a)); } StringBuilder sb = new StringBuilder(); for (String aa : t) { sb.append(aa); } return Integer.parseInt(sb.toString()); }
@prateeksrivastava9
@prateeksrivastava9 4 жыл бұрын
You are doing great job.Keep it up.Thanx!
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@rajarai732
@rajarai732 4 жыл бұрын
Very Helpfull explaination 😉😉
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@funcode-tw3cg
@funcode-tw3cg 2 жыл бұрын
thanks for the easy explaination of this problem !
@vishnuv918
@vishnuv918 3 жыл бұрын
Thank you brother its useful
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@nikitajaiswal9112
@nikitajaiswal9112 2 жыл бұрын
implementation of your approach with edge case consideration class Solution: def largestNumber(self, nums: List[int]) -> str: if all([nums[i]==0 for i in range(len(nums))]): return "0" for i in range(len(nums)-1): for j in range(i+1,len(nums)): ij=str(nums[i])+str(nums[j]) ji=str(nums[j])+str(nums[i]) if ij
@mysteriousocean3206
@mysteriousocean3206 3 жыл бұрын
really awesome explanation sir
@techdose4u
@techdose4u 3 жыл бұрын
Thanks
@gaddar1180
@gaddar1180 2 жыл бұрын
Thanks for sharing the logic ☺
@ShivamKumar-em9nr
@ShivamKumar-em9nr 4 жыл бұрын
Very clear explanation.
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@ayushisharma1381
@ayushisharma1381 4 жыл бұрын
Thanks for this video... Helped a lot :)
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@powersparkmotivation
@powersparkmotivation 4 жыл бұрын
Hi Sir,,, Here we are using 2 loops (one for i and one for j) it's time complexity should be n^2 ....can u illustrate..
@parekshamanchanda8083
@parekshamanchanda8083 4 жыл бұрын
Yes correct, so you can use merge sort instead or stl's sort function with a custom comparator
@alokesh985
@alokesh985 4 жыл бұрын
Say the first loop variable is i and second loop variable is j j starts from i+1 because we do not need to see the previous numbers, so j is decreasing every time we start 2nd loop which is why this is O(nlog(n))
@sudosai
@sudosai 4 жыл бұрын
@@alokesh985 you are wrong. This is similar to bubble sort. The time complexity for the method in the video is :: n+(n-1)+(n-2)+...(1) = n(n-1)/2 = O(n²) Of course you can use quick sort or merge sort to make it O(nlog(n)).
@alokesh985
@alokesh985 4 жыл бұрын
@@sudosai Oh now i see... Thanks. I'll try using quick sort
@deepakvm1475
@deepakvm1475 4 жыл бұрын
@@alokesh985 NOOOO BROO!! its O(n^2)
@cold_water_gaming
@cold_water_gaming Жыл бұрын
That was good teaching.
@baburayhanshaik5121
@baburayhanshaik5121 4 жыл бұрын
i really enjoyed your approach
@techdose4u
@techdose4u 4 жыл бұрын
:)
@rudra9535
@rudra9535 2 жыл бұрын
brilliant work. amazing man.
@i.vigneshdavid1698
@i.vigneshdavid1698 4 жыл бұрын
Thank you for the detail explanation
@techdose4u
@techdose4u 4 жыл бұрын
Nice ☺️ I hope you crack your job too 😀
@i.vigneshdavid1698
@i.vigneshdavid1698 4 жыл бұрын
@@techdose4u 😅yeah i cracked that round.
@techdose4u
@techdose4u 4 жыл бұрын
@@i.vigneshdavid1698 Nice :)
@i.vigneshdavid1698
@i.vigneshdavid1698 4 жыл бұрын
Bro,i was not selected in designing round
@velanganniinbaraj6593
@velanganniinbaraj6593 4 жыл бұрын
Awesome explanation. Thanks a lot.
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@amangoel8724
@amangoel8724 4 жыл бұрын
@TECH DOSE The Time Complexity for sorting is going to be O(N^2)
@techdose4u
@techdose4u 4 жыл бұрын
No...you can sort in NlogN time. Just for the sake of explanation, I took the easiest method.
@amangoel8724
@amangoel8724 4 жыл бұрын
@@techdose4u Thanks got it. Yes you are correct we can do it in nlogn.
@techdose4u
@techdose4u 4 жыл бұрын
:)
@tejaswigutta9017
@tejaswigutta9017 4 жыл бұрын
Aman Goel could you please explain how you did it in nlogn
@abhinavreddy5350
@abhinavreddy5350 4 жыл бұрын
keep doing more tutorials tq .........................................
@techdose4u
@techdose4u 4 жыл бұрын
Thanks for your motivation :)
@harishvenkatesan8751
@harishvenkatesan8751 3 жыл бұрын
Great work man ! Kudos !!
@techdose4u
@techdose4u 3 жыл бұрын
Thanks
@liutian3
@liutian3 4 жыл бұрын
So basically what you demonstrated here is a selection sort but we can also reformulate it into an nlogn sorting method like mergesort based on the defined string comparison rule?
@techdose4u
@techdose4u 4 жыл бұрын
Yea correct. I showed selection sort to clear the other concepts. But you need to select different algo. You can use STL and write the comparator separately which will save you the pain of implementing the entire sorting algo.
@tejuschaturvedi6234
@tejuschaturvedi6234 3 жыл бұрын
Good explained 👍🔥
@techdose4u
@techdose4u 3 жыл бұрын
Thanks
@amermd9254
@amermd9254 3 ай бұрын
Thanks for the explanation, I have a doubt about the sorting process Let's take an example [3,30,34] i = 0, j =1 => 330>303 so we don't swap i = 0, j = 2 => 334 3034 why this condition is not checked, is it every time the condition is satisfied?
@pranavkochhar9352
@pranavkochhar9352 3 жыл бұрын
very good explanation
@pratikwankhade8801
@pratikwankhade8801 3 жыл бұрын
Great solution sir
@sakthim7160
@sakthim7160 4 жыл бұрын
Hello tech dose, I have tried to reduce the time and space complexity of this approach and I have find something. In this approach in order to make swap operation of give two number(string), you are telling to merge and compare like if a and b are given we have to make ab and ba and we have to compare. So for every time we are creating two new string, it won't be efficient know and string compare also will take some time. My approach is that, we have to focus on the the first digit of the given two number, as now we are taking all the number in string format so we can access specific digit very easily. For example If 8 ,120 is given Just compare 8 and 1 and 8 is greater so don't swap 45,56 is given compare 4 and 5 and 5 is great so swap Now if 99 and 98 is given , There is clash in first digit so move to the second digit and compare 9 and 8 now 9 is greater so wap Now if 99 9 is given Here also clash in first digit and we don't have second digit to check in second number. In this case the decision should be taken based on the fully processed number. If first number fully processed no need to swap and if second number fully processed we have to swap. If both are fully processed means both are Same number and no need to swap.
@techdose4u
@techdose4u 4 жыл бұрын
This will be inefficiet and can be complex to implement. If you take an example 21 and 219 then according to you, Number will be 21219 but instead, it should have been 21921. I hope you get it.
@sakthim7160
@sakthim7160 4 жыл бұрын
@@techdose4u I will take this case into consideration and more thing this not an inefficient approach. I have to work on it. Can you explain why are you telling it's inefficient?
@brajkishoredubey9319
@brajkishoredubey9319 3 жыл бұрын
@@sakthim7160 i think your approch looks good , just check size of string for swapping for above scenario (21 and 219 )
@brajkishoredubey9319
@brajkishoredubey9319 3 жыл бұрын
@@techdose4u ​ @Sakthi M i think your approch looks good , just check size of string for swapping for above scenario (21 and 219 ) and then do compare as you mentioned .
@anantpatel8342
@anantpatel8342 4 жыл бұрын
Sir, if i solved it by using the permutations from the itertools library. I generated all the possible numbers from the given elements and stored it in a list, then i sorted the array to get the maximum possible number. Just wanted to ask, is this approch correct? Will this soloution be approved in interviews? The code is - from itertools import permutations arr = [3, 30, 34, 9] arr = list(map(str, arr)) fin = list(permutations(arr, len(arr))) fin = list(map(''.join, [i for i in fin])) fin = list(map(int, fin)) fin.sort(reverse=True) print('The maximum number is',fin[0])
@techdose4u
@techdose4u 4 жыл бұрын
This can work in coding round if STL is allowed but try to use common STLs only in interviews and not these. If you have no resort then you should use it but be ready for the follow-up question to implement permutation 😅
@anantpatel8342
@anantpatel8342 4 жыл бұрын
@@techdose4u Thank you sir.
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@ankitsihag6324
@ankitsihag6324 7 ай бұрын
i think the t.c. will be n! so its better to use this method
@diconicabastion5790
@diconicabastion5790 3 жыл бұрын
If you are simply looking at creating a char string from them your answer is correct. However, if you are looking at them as integers trying to form the largest integer or unsigned integer your answer is wrong. bytes, words and integers all have a specific length. so there are hidden values in them. Well make this simple and assume they are unsigned integers. 0x00000003u = 3, 0x00000022u = 34, 0x00000009u = 9, 0x0000001Eu = 30 thus the largest integer that can be made with them is 0x000000220000001E0000000900000003u or 0x220000001E0000000900000003u or 2,693,757,526,038,389,800,430,435,565,571. Your problem is you used the term array and integer when in a programming reference. For those that don't know what I am talking about integers or int is usually a 32bit sized value. words 16 bits and bytes 8bits. Long int is 64 bits same with long long. you can also have a __uint128_t which is a 128bit unsigned int
@kirtishghosh8950
@kirtishghosh8950 2 жыл бұрын
Very well explained
@abhinabadas7606
@abhinabadas7606 3 жыл бұрын
the sorting technique here is based on selection sort so the time complexity should be n2, how is it nlogn
@techdose4u
@techdose4u 3 жыл бұрын
You can change the sorting technique to make it NlogN
@abhishek__anand__
@abhishek__anand__ Жыл бұрын
Nice Explanation
@tusharkumar3277
@tusharkumar3277 4 жыл бұрын
awesome video man
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@daniekpo
@daniekpo 4 жыл бұрын
I don't get how that's O(n log n). We're pretty much doing an insertion sort which is O(n^2).
@techdose4u
@techdose4u 4 жыл бұрын
It will be N^2 due to string addition which is O(N).
@knightcoder
@knightcoder Жыл бұрын
CODE ==> sort(a.begin(),a.end(), [](int x,int y){ return (stoi(to_string(x)+to_string(y)) > stoi(to_string(y)+to_string(x)));});
@deepukathait6916
@deepukathait6916 4 жыл бұрын
Nice approach sir
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@nithinchitra1570
@nithinchitra1570 Жыл бұрын
superb work bro
@ppujari
@ppujari 4 жыл бұрын
What software do you use for explaining in this video? This is very nice.
@nextgeneration2835
@nextgeneration2835 4 жыл бұрын
respect++; thanks for the video
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@narendrakumariitb
@narendrakumariitb 4 жыл бұрын
Thanks nicely explained. Time complexity won't be O(n*n x O(string comparison)). Since it looks similar like bubble sort
@beautifultime9031
@beautifultime9031 4 жыл бұрын
Narendra Singh but we can pick a sort algorithm such as Quick Sort with the string comparator.
@techdose4u
@techdose4u 4 жыл бұрын
@@beautifultime9031 yea Vishal correct. I explained using selection sort for easy explanation but we need to change the algo (like use Merge sort etc.).
@yyndsai
@yyndsai 3 жыл бұрын
Is there any better algorithm than this?
@geekforgeeks3836
@geekforgeeks3836 4 жыл бұрын
owsome explanation
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@shubhamsumanvishwakarma7113
@shubhamsumanvishwakarma7113 Жыл бұрын
Can we prove transitivity? Say A, B, C are strings, If AB >= BA and BC >= CB then is AC >= CA?
@hoyinli7462
@hoyinli7462 3 жыл бұрын
great explanation. one comment. could you please use standard letter instead of cursive letter? overall great
@techdose4u
@techdose4u 3 жыл бұрын
Sure
@rajeevcbhatia
@rajeevcbhatia 4 жыл бұрын
great explanation sir. i have a question about the complexity of such a sort, seems like every element is compared n times here. does that make the complexity O(n2)? don't native sorting algorithms have an O(NlogN) performance?
@techdose4u
@techdose4u 4 жыл бұрын
O(N^2) because string comparision is O(N)
@rajchaudhary1645
@rajchaudhary1645 4 жыл бұрын
same question came in my mind.
@rajeevcbhatia
@rajeevcbhatia 4 жыл бұрын
@@techdose4u thanks! so would it be NlogN if they are int with this comparator?
@minnuanish9828
@minnuanish9828 3 жыл бұрын
can you explain how to implement the coding also,the append part
@techdose4u
@techdose4u 3 жыл бұрын
You can use string append to solve
@neerajmahapatra5239
@neerajmahapatra5239 2 жыл бұрын
Amazing 👍
@trishulcurtis1810
@trishulcurtis1810 10 ай бұрын
Very Intuitive
@MainakDev
@MainakDev 2 жыл бұрын
I understood the problem but didn’t understand the code, you took 2 strings as input Whats the input should be an Array. I’m confused.
@MainakDev
@MainakDev 2 жыл бұрын
Never mind I’m an idiot
@amitjaiswal6594
@amitjaiswal6594 4 жыл бұрын
Can we sort the array in decreasing order by last digit of every string?
@techdose4u
@techdose4u 4 жыл бұрын
How? If you only compare last digit then what about other digits? Please mention the steps for sorting.
@amitjaiswal6594
@amitjaiswal6594 4 жыл бұрын
@@techdose4u i don't know exactly but i am trying reduce the complexity can we?
@techdose4u
@techdose4u 4 жыл бұрын
I think we need to atleast compare all the elements then only we make a decision for largest number. Sorting does that. Does any other algo do it in less time? Think about it. There might be one.
@subhambanerjee6334
@subhambanerjee6334 3 жыл бұрын
the technique you used is similar to bubble sort so how is this O(N log N) ?
@techdose4u
@techdose4u 3 жыл бұрын
You will use optimized sorting using library
@shourabhpayal1198
@shourabhpayal1198 3 жыл бұрын
We are checking for every i,j pairs. Shouldn't the complexity be n square if strings are considered to be constant len instead of nlogn ?
@techdose4u
@techdose4u 3 жыл бұрын
Actually I have shown simple sort. But you can use optimized search like mergesort implemented in library to get NlogN.
@shourabhpayal1198
@shourabhpayal1198 3 жыл бұрын
@@techdose4u thank you i have figured it out and implemented a custom mergesort as well. If anyone wants to know how let me know.
@techdose4u
@techdose4u 3 жыл бұрын
@@shourabhpayal1198 👍🏼 Share the link for code.
@MilindGupta
@MilindGupta 3 жыл бұрын
@@shourabhpayal1198 please share that code
@shourabhpayal1198
@shourabhpayal1198 3 жыл бұрын
@@MilindGupta I think youtube is removing the link comment
@nobita7231
@nobita7231 4 жыл бұрын
how do calculate time complexity and space complexity Brother??????? Can u teach please
@techdose4u
@techdose4u 4 жыл бұрын
I have uploaded some basic videos on it. Please watch them.
@satyasahoo9573
@satyasahoo9573 4 жыл бұрын
Instead of swapping, if we do insertion, we can get rid of comparision of the same elements multiple times.
@techdose4u
@techdose4u 4 жыл бұрын
🤔 If you have implemented then can you share your code. It will be much more clear that way.
@fazilshafi8083
@fazilshafi8083 7 ай бұрын
Java Folks, here is the complete working solution: class Solution { public class CustomComparator implements Comparator{ @Override public int compare(String a, String b){ String n1 = a+b; String n2 = b+a; return n2.compareTo(n1); } } public String largestNumber(int[] nums) { String[] arr = new String[nums.length]; for(int i=0; i
@tarunkumar.d8379
@tarunkumar.d8379 2 жыл бұрын
Why do we return false when both ij and ji are equal???
@nikitajaiswal9112
@nikitajaiswal9112 2 жыл бұрын
any optimized techinique for this problem??
@prasad.patil12
@prasad.patil12 4 жыл бұрын
How can sorting time is nlogn you are comparing current element with all the rest of the elements shouldn't it be n^2?
@techdose4u
@techdose4u 4 жыл бұрын
Yea N^2. But I just it in a generalized way NlogN. Even adding 2 strings is O(N).
@himankgupta7968
@himankgupta7968 4 жыл бұрын
Can't we find out density of each element (element divided by the number of digits) and then sort them elements on basis of decreasing density...we get same answer O(n)...any case where it will fall?
@ravikant-hi8mz
@ravikant-hi8mz 3 жыл бұрын
Can we have merge sort here? That will also be nlogn
@saumya1singh
@saumya1singh 4 жыл бұрын
GREAT
@techdose4u
@techdose4u 4 жыл бұрын
Thanks
@willturner3440
@willturner3440 3 жыл бұрын
You always rock🤘
@consistentthoughts826
@consistentthoughts826 4 жыл бұрын
Shouldt it be N²logN right as we are traversing the array 1 time
@rajatmishra6628
@rajatmishra6628 4 жыл бұрын
Can be done in O(n) only
@techdose4u
@techdose4u 4 жыл бұрын
Please share the algo
@rishisharma5249
@rishisharma5249 4 жыл бұрын
Is it correct to say that you are sorting using a comparator which compares two numbers formed by appending after each other
@techdose4u
@techdose4u 4 жыл бұрын
I think you can say that (Descending order).
@rishisharma5249
@rishisharma5249 4 жыл бұрын
@@techdose4u Okay, thanks 😊
@deepakvm1475
@deepakvm1475 4 жыл бұрын
bro even on merge sort this takes same no of compriationswhen doin it in c,can you explain whta logic inside that mergeing funtion (i took 1st element from left array and compared all the elements in right array));
@danish829
@danish829 4 жыл бұрын
really helpful
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@rakshith3547
@rakshith3547 4 жыл бұрын
"179. Largest Number" , Please update the description with leetcode number.
@techdose4u
@techdose4u 4 жыл бұрын
I will try.
@rosankumarsenapati3510
@rosankumarsenapati3510 2 жыл бұрын
Hello sir can we do it in this way we will sort it based the 1st digit and we will also have their indices in a map then we itrate over the map and with their indices we can for the number Total time complexity will be O(N)
@rosankumarsenapati3510
@rosankumarsenapati3510 2 жыл бұрын
Correct me if i am wrong
@chiluvurideepthi6822
@chiluvurideepthi6822 2 жыл бұрын
I had implemented this and I was getting TLE .Could you please help me out...
@gauthamarunachalam
@gauthamarunachalam 4 жыл бұрын
The time complexity will be O(N^2)
@Nature-fp7zv
@Nature-fp7zv 4 жыл бұрын
It will be nlogn
@deepakvm1475
@deepakvm1475 4 жыл бұрын
@@Nature-fp7zv how
@MeraBaapHaiTu31
@MeraBaapHaiTu31 4 жыл бұрын
Thnakyou Sir
@techdose4u
@techdose4u 4 жыл бұрын
Welcome
@tanyachhetri9406
@tanyachhetri9406 3 жыл бұрын
how is the time complexity of sorting not n2 but nlogn?
@nikhilsingh5854
@nikhilsingh5854 3 жыл бұрын
Use Merge or Quick sort :)
@NihalSingh-ld2en
@NihalSingh-ld2en 2 жыл бұрын
no the time complexity will not be nlongn, you are simply doing bubble sort, with string comparing.... it is n^2
@rushikeshpujari2364
@rushikeshpujari2364 4 жыл бұрын
sir if the array contain -ve number .(-1-2-3-4)-->o/p will be -1234 but getting {-4,-3,-2,-1} [using your approach]
@gauthamarunachalam
@gauthamarunachalam 4 жыл бұрын
Does radix sort wont work?
@syedkaja2045
@syedkaja2045 4 жыл бұрын
how are u thinking like this pls tell😆
@techdose4u
@techdose4u 4 жыл бұрын
😀 You will become a pro with practice and better than me bro :)
@syedkaja2045
@syedkaja2045 4 жыл бұрын
thanks bro😄
@SomnathDas-fg2qc
@SomnathDas-fg2qc 4 жыл бұрын
cann't we do it least possible approach that means O(N) because the approach which u have explained in worst time comolexity would be very high
@manikantabandla3923
@manikantabandla3923 4 жыл бұрын
We can solve this using radix sort which takes O(n) time
@aadityaupadhyay6264
@aadityaupadhyay6264 4 жыл бұрын
Coursera brings me here GFG got the worst explanation thanks, man
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@rohittopal1498
@rohittopal1498 4 жыл бұрын
same brother
@MeraBaapHaiTu31
@MeraBaapHaiTu31 4 жыл бұрын
Algorithmic Toolbox?
@SameerSk
@SameerSk 4 жыл бұрын
University of California San Diego Algorithm Toolbox squad.
Гениальное изобретение из обычного стаканчика!
00:31
Лютая физика | Олимпиадная физика
Рет қаралды 4,8 МЛН
When you have a very capricious child 😂😘👍
00:16
Like Asiya
Рет қаралды 18 МЛН
Find equilibrium point in an array
10:32
Techdose
Рет қаралды 59 М.
Counting inversions in an array
19:03
Techdose
Рет қаралды 93 М.
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 192 М.
I Solved 100 LeetCode Problems
13:11
Green Code
Рет қаралды 300 М.
How I Mastered Data Structures and Algorithms in 8 Weeks
15:46
Aman Manazir
Рет қаралды 153 М.
Fast Inverse Square Root - A Quake III Algorithm
20:08
Nemean
Рет қаралды 5 МЛН
Минимум математики для Айтишников
16:12
Гениальное изобретение из обычного стаканчика!
00:31
Лютая физика | Олимпиадная физика
Рет қаралды 4,8 МЛН