9 Largest number in K swaps

Поділитися
Вставка
  • Опубліковано 1 жов 2024
  • 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.

КОМЕНТАРІ • 58

  • @lofireverbz-wy7go
    @lofireverbz-wy7go 9 місяців тому +11

    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??????????

  • @mohit6215
    @mohit6215 9 місяців тому +8

    The legend(Aditya verma)will always come back for us❤❤

  • @ravirayal7590
    @ravirayal7590 9 місяців тому +10

    So happy to see you again making videos ❤❤

  • @divyanshmishra5121
    @divyanshmishra5121 8 місяців тому +10

    please upload next videos. Its been more than a month. We've placements this year. Atleast complete this series.

    • @shreyashj.sharma9746
      @shreyashj.sharma9746 6 місяців тому +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 2 місяці тому

      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

  • @rishabhahuja7413
    @rishabhahuja7413 9 місяців тому +6

    Bhai Graphs and Trees please🙏

  • @Dezy_Kri
    @Dezy_Kri 8 місяців тому +3

    Aditya Bhaiya kar do upload videos bahut din ho gye🥲

  • @pinkysinghala
    @pinkysinghala 8 місяців тому +3

    Bhaiya 27 video of dp not uploaded plz upload it 🛑🛑

  • @divyanshmishra5121
    @divyanshmishra5121 9 місяців тому +4

    bhaaiii subah se 10 baar check chuka tha for new video as there was no video since last 10 days. finallyy!

  • @Raj10185
    @Raj10185 9 місяців тому +4

    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 9 місяців тому +2

      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;
      }
      };

  • @RohitSharma-u2q5q
    @RohitSharma-u2q5q 4 дні тому

    watching this video from mata mandir aditya bhiya know about this place

  • @ymanojx
    @ymanojx 8 місяців тому +3

    CEO of voice recording

  • @ronitkaushik4634
    @ronitkaushik4634 2 місяці тому +1

    those who know why it isnt greedy watch from 08:24

  • @pinkysinghala
    @pinkysinghala 8 місяців тому +1

    Bhaiya sequence pattern matching ka recursive version jo aapne 31 video of dp m kha tha upload krne ko plz upload it 🛑🛑🛑🛑

  • @janakiramireddikoki7084
    @janakiramireddikoki7084 Місяць тому

    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 15 днів тому

      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.

  • @paradoxOP1002
    @paradoxOP1002 9 місяців тому +1

    kisi pe problem link ho toh plz dena. thanks in advance :)

  • @shravani2922
    @shravani2922 8 місяців тому +1

    Hi when will you complete the dp series?

  • @simnidhnidh9122
    @simnidhnidh9122 2 місяці тому

    Aapne bhaiya bhaut ache se explain kiya especially that similarity and dissimilarity ig no can can explain like this in this whole youtube community

  • @someshpatel7660
    @someshpatel7660 24 дні тому

    Man we need more people like you. For any DSA topic I first search it with your name. Thanks for all your efforts. 🔥🔥🔥🔥

  • @thesyazah
    @thesyazah 8 місяців тому +1

    please upload the next video

  • @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.

  • @abhayjoshi362
    @abhayjoshi362 9 місяців тому +1

    Again amazing video well explained 🔥🔥 or ha biyaah nhi hua haii😂🤣

  • @RitikaMajumdar__F
    @RitikaMajumdar__F 2 місяці тому

    Jb maine phele question video ke baad yeh video dekha kya gajab ka smjh aya 💯💯

  • @PiyushCodes-ph3hl
    @PiyushCodes-ph3hl 8 місяців тому

    @Aditya Verma please complete the DP series as well 🙏🙏🙏

  • @chandrasekar-ft9br
    @chandrasekar-ft9br 9 місяців тому

    Can you please make a video in ENGLISH

  • @shashanksuman6804
    @shashanksuman6804 3 місяці тому

    Sare problem tumne solve ni kiya 😢

  • @riturajtrivedi7851
    @riturajtrivedi7851 8 місяців тому

    Adi bhaiya at this point I doubt kisi aur youtuber ko DSA aata bhbi tha ya nahi 🥲

  • @PiyushCodes-ph3hl
    @PiyushCodes-ph3hl 8 місяців тому

    bhaiya please DP series complete kardo

  • @onechance5664
    @onechance5664 Місяць тому

    14:17 was funny "fhaaltu bakwaas hai"😂

  • @PiyushCodes-ph3hl
    @PiyushCodes-ph3hl 8 місяців тому

    bhaiya please DP series complete kardo

  • @ujjwalkatiyar3249
    @ujjwalkatiyar3249 7 місяців тому

    Kese ne notes banae hai kya ?
    Please share kar do

  • @dhonimsd9506
    @dhonimsd9506 9 місяців тому +4

    Can you explain in English or add English subtitles so that non Hindi people like me can understand 😊

  • @SagarMishra-r6h
    @SagarMishra-r6h 3 місяці тому

    Best Line - 22:32 🤣🤣

  • @amarjeetyadav7783
    @amarjeetyadav7783 4 місяці тому

    Bade dharmik vyakti ho @Aditya Verma. Backtracking me bh dharam ki baat.

  • @aishwaryacj5683
    @aishwaryacj5683 8 місяців тому

    Please continue to make vedios.. Strings , Queues , Trees Please cover this topic please

  • @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.

  • @nitinchoudhary3549
    @nitinchoudhary3549 9 місяців тому

    Bhaiya roz ya alternate days video daala karo plss..

  • @ankurrajput2367
    @ankurrajput2367 8 місяців тому

    Finally legend back 🎉

  • @rohitronte2405
    @rohitronte2405 9 місяців тому

    Hi again😍

  • @sumitbasu5146
    @sumitbasu5146 4 місяці тому

    Tree Tree Tree Please please please

  • @_desouvik
    @_desouvik 5 місяців тому

    Biyah kar liya DSA ke sath, Unsubscribe kardu kya?

  • @TanuKansal-nn4el
    @TanuKansal-nn4el 9 місяців тому

    Is this question on leetcode?

  • @naveedwaddo8817
    @naveedwaddo8817 8 місяців тому +1

    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 8 місяців тому

      bro why did u add that no swapping statement. Can u explain ?

    • @naveedwaddo8817
      @naveedwaddo8817 8 місяців тому +1

      ​@@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 8 місяців тому

      ​@@naveedwaddo8817 Thanks man for the answer

  • @Rohankumar-dd2ss
    @Rohankumar-dd2ss 9 місяців тому

    Tu jinda he