9 Largest number in K swaps

  Рет қаралды 15,607

Aditya Verma

Aditya Verma

Күн бұрын

Given a number K and string str of digits denoting a positive integer, build the largest number possible by performing swap operations on the digits of str at most K times.
Example 1:
Input:
K = 4
str = "1234567"
Output:
7654321
Explanation:
Three swaps can make the
input 1234567 to 7654321, swapping 1
with 7, 2 with 6 and finally 3 with 5
------------------------------------------------------------------------------------------
Here are some of the gears that I use almost everyday:
🖊️ : My Pen (Used in videos too): amzn.to/38fKSM1
👨🏻‍💻 : My Apple Macbook pro: amzn.to/3w8iZh6
💻 : My gaming laptop: amzn.to/3yjcn23
📱 : My Ipad: amzn.to/39yEMGS
✏️ : My Apple Pencil: amzn.to/3kMnKYf
🎧 : My Headphones: amzn.to/3kMOzM7
💺 : My Chair: amzn.to/385weqR
🛋 : My Table: amzn.to/3TyU2IU
⏰ : My Clock: amzn.to/3slFUV3
🙋🏻‍♀️ : My girlfriend: amzn.to/3M6zLDK ¯\_(ツ)_/¯
PS: While having good gears help you perform efficiently, don’t get under the impression that they will make you successful without any hard work.

Пікірлер: 57
@someshpatel7660
@someshpatel7660 10 күн бұрын
Man we need more people like you. For any DSA topic I first search it with your name. Thanks for all your efforts. 🔥🔥🔥🔥
@ravirayal7590
@ravirayal7590 8 ай бұрын
So happy to see you again making videos ❤❤
@simnidhnidh9122
@simnidhnidh9122 Ай бұрын
Aapne bhaiya bhaut ache se explain kiya especially that similarity and dissimilarity ig no can can explain like this in this whole youtube community
@divyanshmishra5121
@divyanshmishra5121 8 ай бұрын
bhaaiii subah se 10 baar check chuka tha for new video as there was no video since last 10 days. finallyy!
@onechance5664
@onechance5664 20 күн бұрын
14:17 was funny "fhaaltu bakwaas hai"😂
@Raj10185
@Raj10185 8 ай бұрын
Bhot behterren question hai ye Backtracking ka pura hi concept clear kar diya . Bhut sare edgePoints hai isme ab iska code khud se try karta hai . Accept ho jyega to maza aa jyega
@Raj10185
@Raj10185 8 ай бұрын
yes i finally i am able to do it :- class Solution { public: //Function to find the largest number after k swaps. string maxi = ""; void solve(int idx , string &str , int k) { if ( idx == str.size()-1 or k==0){ maxi = max(maxi,str); return; } for(int i = idx+1 ; i < str.size();i++) { char maxiChar = *max_element(str.begin()+i,str.end()); if(str[i] > str[idx] && str[i]==maxiChar) { swap(str[i],str[idx]); solve(idx+1,str,k-1); swap(str[i],str[idx]); } } //agar loop se kaam nhi hua solve(idx+1,str,k); } string findMaximumNum(string str, int k) { string temp = ""; solve(0,str,k); return maxi; } };
@11siddhesh
@11siddhesh Ай бұрын
I like your videos a lot, I have a constructive feedback: same explanation is repeated multiple times which makes the video longer than it should be.
@lofireverbz-wy7go
@lofireverbz-wy7go 8 ай бұрын
bhaiya ek humble request hai bus ye btado backtracking ke bddd konsi playlist aeegi taaki vo topic khi or se na pdhu jab tak please bhaiya graph ya tree konsi aegi bhaiya??????????
@mithileshkumar9653
@mithileshkumar9653 7 ай бұрын
tree
@RitikaMajumdar__F
@RitikaMajumdar__F 2 ай бұрын
Jb maine phele question video ke baad yeh video dekha kya gajab ka smjh aya 💯💯
@divyanshmishra5121
@divyanshmishra5121 7 ай бұрын
please upload next videos. Its been more than a month. We've placements this year. Atleast complete this series.
@shreyashj.sharma9746
@shreyashj.sharma9746 5 ай бұрын
he's a working professional doing this on the side for free for students such as yourself, be grateful and stop demanding.
@thorxn1382
@thorxn1382 Ай бұрын
Free ka mile toh aur mangte hain
@divyanshmishra5121
@divyanshmishra5121 Ай бұрын
@@shreyashj.sharma9746 bhai tu thoda sa bkl hai kya? request hi toh kar rha tha main. teri kyu jal rhi bhai
@mohit6215
@mohit6215 8 ай бұрын
The legend(Aditya verma)will always come back for us❤❤
@rishabhahuja7413
@rishabhahuja7413 8 ай бұрын
Bhai Graphs and Trees please🙏
@abhayjoshi362
@abhayjoshi362 8 ай бұрын
Again amazing video well explained 🔥🔥 or ha biyaah nhi hua haii😂🤣
@ymanojx
@ymanojx 8 ай бұрын
CEO of voice recording
@shravani2922
@shravani2922 7 ай бұрын
Hi when will you complete the dp series?
@pinkysinghala
@pinkysinghala 8 ай бұрын
Bhaiya 27 video of dp not uploaded plz upload it 🛑🛑
@PiyushCodes-ph3hl
@PiyushCodes-ph3hl 7 ай бұрын
@Aditya Verma please complete the DP series as well 🙏🙏🙏
@janakiramireddikoki7084
@janakiramireddikoki7084 29 күн бұрын
Did not understood why it's not a greedy choice. If we have 1 swap and number is 4577 then you will always swap 4 with last 7 then only the largest number comes. Ex: 4577 => 7574 if we swap with first 7, 4577 => 7547 which is not largest. So you will always swap with last largest no. Please correct me if i missed something
@SnoW-bk1zn
@SnoW-bk1zn Күн бұрын
he is saying if there are only 2 swaps 4577 -------- with greedy 1st swap (4 with first 7) - 7547 2nd swap( 5 with 7) - 7745 -------- with backtracking(backtracking considers all the combinations) -1st combination 1st swap (4 with first 7) - 7547 2nd swap( 5 with 7) - 7745 -2nd combination 1st swap (4 with second 7) - 7574 2nd swap( 5 with 7) - 7754 *** now with backtracking we are able to find the largest I think this is it , but I don't have much knowledge about greedy so I may also be wrong.
@pinkysinghala
@pinkysinghala 8 ай бұрын
Bhaiya sequence pattern matching ka recursive version jo aapne 31 video of dp m kha tha upload krne ko plz upload it 🛑🛑🛑🛑
@Dezy_Kri
@Dezy_Kri 8 ай бұрын
Aditya Bhaiya kar do upload videos bahut din ho gye🥲
@thesyazah
@thesyazah 7 ай бұрын
please upload the next video
@aishwaryacj5683
@aishwaryacj5683 8 ай бұрын
Please continue to make vedios.. Strings , Queues , Trees Please cover this topic please
@solarsystem9156
@solarsystem9156 2 ай бұрын
videos* :)
@ujjwalkatiyar3249
@ujjwalkatiyar3249 6 ай бұрын
Kese ne notes banae hai kya ? Please share kar do
@ronitkaushik4634
@ronitkaushik4634 2 ай бұрын
those who know why it isnt greedy watch from 08:24
@user-tl2be3ho9s
@user-tl2be3ho9s 2 ай бұрын
Best Line - 22:32 🤣🤣
@ankurrajput2367
@ankurrajput2367 8 ай бұрын
Finally legend back 🎉
@PiyushCodes-ph3hl
@PiyushCodes-ph3hl 7 ай бұрын
bhaiya please DP series complete kardo
@nitinchoudhary3549
@nitinchoudhary3549 8 ай бұрын
Bhaiya roz ya alternate days video daala karo plss..
@mehulsuthar7554
@mehulsuthar7554 8 ай бұрын
bhaiya i have one question, so i have started cp and getting quite good at it(currently at dp). i am studying bsc cs third year I was searching for the internship online and I am see everywhere that they mostly require some kind of framework more than the coding skill I am losing motivation to study cp tbh, also quite confused with this things. I want to get a job programming job please can you help with this? ik that cp is important and all for efficient and good coding skills but I am confused now.
@RohitKumar-kj3yl
@RohitKumar-kj3yl 8 ай бұрын
same with me too
@munvut877
@munvut877 8 ай бұрын
bro maintain both like learn atleast one web framework like React,Angular.
@paradoxOP1002
@paradoxOP1002 8 ай бұрын
kisi pe problem link ho toh plz dena. thanks in advance :)
@riturajtrivedi7851
@riturajtrivedi7851 8 ай бұрын
Adi bhaiya at this point I doubt kisi aur youtuber ko DSA aata bhbi tha ya nahi 🥲
@TanuKansal-nn4el
@TanuKansal-nn4el 8 ай бұрын
Is this question on leetcode?
@bommakantibeeraiah1486
@bommakantibeeraiah1486 4 ай бұрын
geeksforgeeks
@dhonimsd9506
@dhonimsd9506 8 ай бұрын
Can you explain in English or add English subtitles so that non Hindi people like me can understand 😊
@sumitbasu5146
@sumitbasu5146 4 ай бұрын
Tree Tree Tree Please please please
@solarsystem9156
@solarsystem9156 2 ай бұрын
Plant a seed :)
@shashanksuman6804
@shashanksuman6804 3 ай бұрын
Sare problem tumne solve ni kiya 😢
@chandrasekar-ft9br
@chandrasekar-ft9br 8 ай бұрын
Can you please make a video in ENGLISH
@rohitronte2405
@rohitronte2405 8 ай бұрын
Hi again😍
@amarjeetyadav7783
@amarjeetyadav7783 3 ай бұрын
Bade dharmik vyakti ho @Aditya Verma. Backtracking me bh dharam ki baat.
@naveedwaddo8817
@naveedwaddo8817 8 ай бұрын
class Solution{ private: void solve(int start , string &s , int k , string &ans){ if(k==0 || start==s.size()){ ans = max(ans , s); return; } char maxVal = s[start]; for(int j=start+1; j
@aryanmittal5676
@aryanmittal5676 7 ай бұрын
bro why did u add that no swapping statement. Can u explain ?
@naveedwaddo8817
@naveedwaddo8817 7 ай бұрын
​@@aryanmittal5676 statements Means : Move on to the next index (start+1) without making a swap at the current index. Explanation : The following code for exploring the possibilties for swap : for(int i=start+1; i s[start] && s[i]==maxVal){ swap(s[start] , s[i]); solve(start+1 , s , k-1 , ans); swap(s[start] , s[i]); } } lets suppose the if condition inside the forloop is not true for a atleast once then our recursion is not calling for next start+1. that case is s[start] > s[start+1,....n] then there no need to swap the s[start] with s[start+1 ,...n] so the problem is how can i call the recursion without making swap , so to do so we call the recursion with the line solve(start+1 , s , k , ans); // no swappting.
@aryanmittal5676
@aryanmittal5676 7 ай бұрын
​@@naveedwaddo8817 Thanks man for the answer
@_desouvik
@_desouvik 4 ай бұрын
Biyah kar liya DSA ke sath, Unsubscribe kardu kya?
@CSBASHUTIWARI
@CSBASHUTIWARI Ай бұрын
😅😅
@Rohankumar-dd2ss
@Rohankumar-dd2ss 8 ай бұрын
Tu jinda he
@PiyushCodes-ph3hl
@PiyushCodes-ph3hl 7 ай бұрын
bhaiya please DP series complete kardo
10 Largest number in K swaps Code and Time Complexity
30:38
Aditya Verma
Рет қаралды 8 М.
Je peux le faire
00:13
Daniil le Russe
Рет қаралды 21 МЛН
Brawl Stars Edit😈📕
00:15
Kan Andrey
Рет қаралды 45 МЛН
5 01 Knapsack Top Down DP
41:08
Aditya Verma
Рет қаралды 600 М.
11 N Digit numbers with digits in increasing order
32:24
Aditya Verma
Рет қаралды 8 М.
Minimum Window Substring | Variable Size Sliding Window
40:35
Aditya Verma
Рет қаралды 199 М.
24 Shortest Common SuperSequence
22:59
Aditya Verma
Рет қаралды 195 М.
6 Permutation of Strings | Simple Recursion
39:00
Aditya Verma
Рет қаралды 24 М.
36  Palindrome Partitioning Recursive
26:35
Aditya Verma
Рет қаралды 193 М.