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.
@techdose4u4 жыл бұрын
Thanks :) I will try my best to keep it as frequent as possible.
@faizanhassan20884 жыл бұрын
@@techdose4u He is absolutely right, Sir.
@nikhilkumarjamwal5322 Жыл бұрын
@@techdose4u O(n^2)? Can you explain how it is O(n)?
@akshatjain68544 жыл бұрын
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.
@jiteshkumar31124 жыл бұрын
best channel who's main motive is to tell approach and clear the concept..thanks you Sir!
@techdose4u4 жыл бұрын
Welcome :)
@jiteshkumar31124 жыл бұрын
@@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-ff4hf4 жыл бұрын
Thanks for doing the inner explanation of Comparator..i was unhappy about geeksforgeeks explanation..but you cleared it👍
@techdose4u4 жыл бұрын
Welcome :)
@anilchaudhry8044 жыл бұрын
Exactly
@deepikadhamija45484 жыл бұрын
They way u explain things , clear all the doubts. Thnx for making such explanatory videos
@techdose4u4 жыл бұрын
Welcome
@blazedcosmicgoat52263 жыл бұрын
for those saying it's O(N2) just implement the same logic in mergesort inside the merge function and you will have nlogn complexity.
@mobilesuniverse2 жыл бұрын
yeh sabse best video hai, bhaut jagah solution deka , samaj ni aya, vector hashmap use kar rhe the
@alokesh9854 жыл бұрын
Excellent video. Couldn't find a better explanation online!
@techdose4u4 жыл бұрын
Welcome
@cseengineering85822 жыл бұрын
your voice and explanation both are so clear, this thing attracts me to this channel.
@ShreyaSingh-vr9qi4 жыл бұрын
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.
@techdose4u4 жыл бұрын
Thanks :) The time complexity will be O(NlogN) because you will use Merge sort. I just chose it for simplicity.
@vaibhavjain792 жыл бұрын
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
@akshayapanda23422 жыл бұрын
Please don't provide wrong information, Do you think the sorting technique you have used here will give nlogn time complexity?
@RIPNANI3 ай бұрын
N*N😢
@blume0f4 жыл бұрын
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!
@techdose4u4 жыл бұрын
Thanks :)
@Thorfin123464 жыл бұрын
its O(n^2)
@naresh455443 жыл бұрын
Exactly. This is basically selection sort with the special comparison.
@saitejaballa67593 жыл бұрын
Using merge sort with custom sort operation is O(nlogn)
@varunnarayanan87204 жыл бұрын
Some kind of Bubble sort is used here but the logic is explained which is the most important part. Very good video
@robertsedgewick12663 жыл бұрын
Very clear explanation. Makes the solution so intuitive!
@techdose4u3 жыл бұрын
Thanks :)
@rhythmbhandari85493 жыл бұрын
The explanation is pretty much simple and easy Thank you
@techdose4u3 жыл бұрын
Welcome :)
@rohittopal14984 жыл бұрын
wooow , When i read question It seems very hard after I watched this video . It is very easy for me
@davidjonson303 Жыл бұрын
Thanks sir ..for such video Your video is so easy to understand and help us a lot
@CodeSuccessChronicle3 жыл бұрын
You’re my motivation to start coding.... thank you so much please keep inspiring us with your intuition.....
@techdose4u3 жыл бұрын
Welcome :)
@dineshs24849 ай бұрын
This technique will surely take o(n*2) as there is two loops comparing the eeach elements.but the solution was easy to understand.
@mausham54494 жыл бұрын
u really explain very well.thanks. plz keep posting regularly.
@techdose4u4 жыл бұрын
Thanks....sure I am posting regularly.
@ihopethiscommentisntabusiv46703 жыл бұрын
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!
@techdose4u3 жыл бұрын
:)
@akashpradipj2 жыл бұрын
@@techdose4u in case of merge sort, how you are going to include the comparison of two strings based on their integer representation?
@goutamkundu63923 жыл бұрын
Great explanation Surya. Really liking your channel. Respect from your past colleague.
@techdose4u3 жыл бұрын
Thanks Goutam ❤️
@techacemidhun4 жыл бұрын
// 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; } };
@varsha90944 жыл бұрын
is this c++?
@ryanaugustine59402 жыл бұрын
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()); }
@prateeksrivastava94 жыл бұрын
You are doing great job.Keep it up.Thanx!
@techdose4u4 жыл бұрын
Welcome :)
@rajarai7324 жыл бұрын
Very Helpfull explaination 😉😉
@techdose4u4 жыл бұрын
Thanks :)
@funcode-tw3cg2 жыл бұрын
thanks for the easy explaination of this problem !
@vishnuv9183 жыл бұрын
Thank you brother its useful
@techdose4u3 жыл бұрын
Welcome :)
@nikitajaiswal91122 жыл бұрын
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
@mysteriousocean32063 жыл бұрын
really awesome explanation sir
@techdose4u3 жыл бұрын
Thanks
@gaddar11802 жыл бұрын
Thanks for sharing the logic ☺
@ShivamKumar-em9nr4 жыл бұрын
Very clear explanation.
@techdose4u4 жыл бұрын
Thanks :)
@ayushisharma13814 жыл бұрын
Thanks for this video... Helped a lot :)
@techdose4u4 жыл бұрын
Welcome :)
@powersparkmotivation4 жыл бұрын
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..
@parekshamanchanda80834 жыл бұрын
Yes correct, so you can use merge sort instead or stl's sort function with a custom comparator
@alokesh9854 жыл бұрын
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))
@sudosai4 жыл бұрын
@@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)).
@alokesh9854 жыл бұрын
@@sudosai Oh now i see... Thanks. I'll try using quick sort
@deepakvm14754 жыл бұрын
@@alokesh985 NOOOO BROO!! its O(n^2)
@cold_water_gaming Жыл бұрын
That was good teaching.
@baburayhanshaik51214 жыл бұрын
i really enjoyed your approach
@techdose4u4 жыл бұрын
:)
@rudra95352 жыл бұрын
brilliant work. amazing man.
@i.vigneshdavid16984 жыл бұрын
Thank you for the detail explanation
@techdose4u4 жыл бұрын
Nice ☺️ I hope you crack your job too 😀
@i.vigneshdavid16984 жыл бұрын
@@techdose4u 😅yeah i cracked that round.
@techdose4u4 жыл бұрын
@@i.vigneshdavid1698 Nice :)
@i.vigneshdavid16984 жыл бұрын
Bro,i was not selected in designing round
@velanganniinbaraj65934 жыл бұрын
Awesome explanation. Thanks a lot.
@techdose4u4 жыл бұрын
Welcome :)
@amangoel87244 жыл бұрын
@TECH DOSE The Time Complexity for sorting is going to be O(N^2)
@techdose4u4 жыл бұрын
No...you can sort in NlogN time. Just for the sake of explanation, I took the easiest method.
@amangoel87244 жыл бұрын
@@techdose4u Thanks got it. Yes you are correct we can do it in nlogn.
@techdose4u4 жыл бұрын
:)
@tejaswigutta90174 жыл бұрын
Aman Goel could you please explain how you did it in nlogn
@abhinavreddy53504 жыл бұрын
keep doing more tutorials tq .........................................
@techdose4u4 жыл бұрын
Thanks for your motivation :)
@harishvenkatesan87513 жыл бұрын
Great work man ! Kudos !!
@techdose4u3 жыл бұрын
Thanks
@liutian34 жыл бұрын
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?
@techdose4u4 жыл бұрын
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.
@tejuschaturvedi62343 жыл бұрын
Good explained 👍🔥
@techdose4u3 жыл бұрын
Thanks
@amermd92543 ай бұрын
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?
@pranavkochhar93523 жыл бұрын
very good explanation
@pratikwankhade88013 жыл бұрын
Great solution sir
@sakthim71604 жыл бұрын
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.
@techdose4u4 жыл бұрын
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.
@sakthim71604 жыл бұрын
@@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?
@brajkishoredubey93193 жыл бұрын
@@sakthim7160 i think your approch looks good , just check size of string for swapping for above scenario (21 and 219 )
@brajkishoredubey93193 жыл бұрын
@@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 .
@anantpatel83424 жыл бұрын
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])
@techdose4u4 жыл бұрын
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 😅
@anantpatel83424 жыл бұрын
@@techdose4u Thank you sir.
@techdose4u4 жыл бұрын
Welcome :)
@ankitsihag63247 ай бұрын
i think the t.c. will be n! so its better to use this method
@diconicabastion57903 жыл бұрын
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
@kirtishghosh89502 жыл бұрын
Very well explained
@abhinabadas76063 жыл бұрын
the sorting technique here is based on selection sort so the time complexity should be n2, how is it nlogn
@techdose4u3 жыл бұрын
You can change the sorting technique to make it NlogN
@abhishek__anand__ Жыл бұрын
Nice Explanation
@tusharkumar32774 жыл бұрын
awesome video man
@techdose4u4 жыл бұрын
Thanks :)
@daniekpo4 жыл бұрын
I don't get how that's O(n log n). We're pretty much doing an insertion sort which is O(n^2).
@techdose4u4 жыл бұрын
It will be N^2 due to string addition which is O(N).
What software do you use for explaining in this video? This is very nice.
@nextgeneration28354 жыл бұрын
respect++; thanks for the video
@techdose4u4 жыл бұрын
Welcome :)
@narendrakumariitb4 жыл бұрын
Thanks nicely explained. Time complexity won't be O(n*n x O(string comparison)). Since it looks similar like bubble sort
@beautifultime90314 жыл бұрын
Narendra Singh but we can pick a sort algorithm such as Quick Sort with the string comparator.
@techdose4u4 жыл бұрын
@@beautifultime9031 yea Vishal correct. I explained using selection sort for easy explanation but we need to change the algo (like use Merge sort etc.).
@yyndsai3 жыл бұрын
Is there any better algorithm than this?
@geekforgeeks38364 жыл бұрын
owsome explanation
@techdose4u4 жыл бұрын
Thanks :)
@shubhamsumanvishwakarma7113 Жыл бұрын
Can we prove transitivity? Say A, B, C are strings, If AB >= BA and BC >= CB then is AC >= CA?
@hoyinli74623 жыл бұрын
great explanation. one comment. could you please use standard letter instead of cursive letter? overall great
@techdose4u3 жыл бұрын
Sure
@rajeevcbhatia4 жыл бұрын
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?
@techdose4u4 жыл бұрын
O(N^2) because string comparision is O(N)
@rajchaudhary16454 жыл бұрын
same question came in my mind.
@rajeevcbhatia4 жыл бұрын
@@techdose4u thanks! so would it be NlogN if they are int with this comparator?
@minnuanish98283 жыл бұрын
can you explain how to implement the coding also,the append part
@techdose4u3 жыл бұрын
You can use string append to solve
@neerajmahapatra52392 жыл бұрын
Amazing 👍
@trishulcurtis181010 ай бұрын
Very Intuitive
@MainakDev2 жыл бұрын
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.
@MainakDev2 жыл бұрын
Never mind I’m an idiot
@amitjaiswal65944 жыл бұрын
Can we sort the array in decreasing order by last digit of every string?
@techdose4u4 жыл бұрын
How? If you only compare last digit then what about other digits? Please mention the steps for sorting.
@amitjaiswal65944 жыл бұрын
@@techdose4u i don't know exactly but i am trying reduce the complexity can we?
@techdose4u4 жыл бұрын
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.
@subhambanerjee63343 жыл бұрын
the technique you used is similar to bubble sort so how is this O(N log N) ?
@techdose4u3 жыл бұрын
You will use optimized sorting using library
@shourabhpayal11983 жыл бұрын
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 ?
@techdose4u3 жыл бұрын
Actually I have shown simple sort. But you can use optimized search like mergesort implemented in library to get NlogN.
@shourabhpayal11983 жыл бұрын
@@techdose4u thank you i have figured it out and implemented a custom mergesort as well. If anyone wants to know how let me know.
@techdose4u3 жыл бұрын
@@shourabhpayal1198 👍🏼 Share the link for code.
@MilindGupta3 жыл бұрын
@@shourabhpayal1198 please share that code
@shourabhpayal11983 жыл бұрын
@@MilindGupta I think youtube is removing the link comment
@nobita72314 жыл бұрын
how do calculate time complexity and space complexity Brother??????? Can u teach please
@techdose4u4 жыл бұрын
I have uploaded some basic videos on it. Please watch them.
@satyasahoo95734 жыл бұрын
Instead of swapping, if we do insertion, we can get rid of comparision of the same elements multiple times.
@techdose4u4 жыл бұрын
🤔 If you have implemented then can you share your code. It will be much more clear that way.
@fazilshafi80837 ай бұрын
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.d83792 жыл бұрын
Why do we return false when both ij and ji are equal???
@nikitajaiswal91122 жыл бұрын
any optimized techinique for this problem??
@prasad.patil124 жыл бұрын
How can sorting time is nlogn you are comparing current element with all the rest of the elements shouldn't it be n^2?
@techdose4u4 жыл бұрын
Yea N^2. But I just it in a generalized way NlogN. Even adding 2 strings is O(N).
@himankgupta79684 жыл бұрын
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-hi8mz3 жыл бұрын
Can we have merge sort here? That will also be nlogn
@saumya1singh4 жыл бұрын
GREAT
@techdose4u4 жыл бұрын
Thanks
@willturner34403 жыл бұрын
You always rock🤘
@consistentthoughts8264 жыл бұрын
Shouldt it be N²logN right as we are traversing the array 1 time
@rajatmishra66284 жыл бұрын
Can be done in O(n) only
@techdose4u4 жыл бұрын
Please share the algo
@rishisharma52494 жыл бұрын
Is it correct to say that you are sorting using a comparator which compares two numbers formed by appending after each other
@techdose4u4 жыл бұрын
I think you can say that (Descending order).
@rishisharma52494 жыл бұрын
@@techdose4u Okay, thanks 😊
@deepakvm14754 жыл бұрын
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));
@danish8294 жыл бұрын
really helpful
@techdose4u4 жыл бұрын
Thanks :)
@rakshith35474 жыл бұрын
"179. Largest Number" , Please update the description with leetcode number.
@techdose4u4 жыл бұрын
I will try.
@rosankumarsenapati35102 жыл бұрын
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)
@rosankumarsenapati35102 жыл бұрын
Correct me if i am wrong
@chiluvurideepthi68222 жыл бұрын
I had implemented this and I was getting TLE .Could you please help me out...
@gauthamarunachalam4 жыл бұрын
The time complexity will be O(N^2)
@Nature-fp7zv4 жыл бұрын
It will be nlogn
@deepakvm14754 жыл бұрын
@@Nature-fp7zv how
@MeraBaapHaiTu314 жыл бұрын
Thnakyou Sir
@techdose4u4 жыл бұрын
Welcome
@tanyachhetri94063 жыл бұрын
how is the time complexity of sorting not n2 but nlogn?
@nikhilsingh58543 жыл бұрын
Use Merge or Quick sort :)
@NihalSingh-ld2en2 жыл бұрын
no the time complexity will not be nlongn, you are simply doing bubble sort, with string comparing.... it is n^2
@rushikeshpujari23644 жыл бұрын
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]
@gauthamarunachalam4 жыл бұрын
Does radix sort wont work?
@syedkaja20454 жыл бұрын
how are u thinking like this pls tell😆
@techdose4u4 жыл бұрын
😀 You will become a pro with practice and better than me bro :)
@syedkaja20454 жыл бұрын
thanks bro😄
@SomnathDas-fg2qc4 жыл бұрын
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
@manikantabandla39234 жыл бұрын
We can solve this using radix sort which takes O(n) time
@aadityaupadhyay62644 жыл бұрын
Coursera brings me here GFG got the worst explanation thanks, man
@techdose4u4 жыл бұрын
Welcome :)
@rohittopal14984 жыл бұрын
same brother
@MeraBaapHaiTu314 жыл бұрын
Algorithmic Toolbox?
@SameerSk4 жыл бұрын
University of California San Diego Algorithm Toolbox squad.