Permutation Sequence | Leetcode #60

Sdílet
Vložit
  • čas přidán 19. 06. 2020
  • This video explains an important programming interview problem which is to find the Kth permutation of a string of length N. In this problem, we are given number of digits N and Kth permutation to be found K.We can simply generate the permutations from the beginning and find Kth permutation.But this method will take a lot of time which is O(N!).This is not feasible.We can apply some mathematical intuition to solve this problem in just O(1).I have shown the intuition and method for solving this problem in the most efficient way.I have explained the algorithm with proper examples and at the end of the video, i have shown the code walk through.CODE LINK is present below as usual. If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)
    =================================================================
    INSTAGRAM: / surya.pratap.k
    LinkedIn: / surya-pratap-kahar-47b...
    =================================================================
    CODE LINK: gist.github.com/SuryaPratapK/...
    SIMILAR PROBLEMS:-
    String Permutation Algorithm: • String permutation alg...

Komentáře • 90

  • @100bands
    @100bands Před 4 lety +62

    I live for the day I can come with solutions like this myself. Kudos man and thanks for making these videos

    • @techdose4u
      @techdose4u  Před 4 lety +11

      😅 Man you will do it in some time.

    • @skybirdnomad
      @skybirdnomad Před 3 lety +5

      Just keep practicing and you will do it! But don't just watch the video to know the answer, try as hard as possible to figure it out yourself, and then when you're ABSOLUTELY stuck then watch the video
      You got it brother

  • @vivekthakur1953
    @vivekthakur1953 Před 3 lety +5

    I searched the question on youtube, found many popular CZcamsrs with the explanation video. But my heart knew which video to land on!!

  • @AnuragBhattacharjee07061
    @AnuragBhattacharjee07061 Před 4 lety +2

    You did a great job of explaining the algorithm.

  • @cicciopasticcio8469
    @cicciopasticcio8469 Před 4 lety +12

    I just watched the first part, it gave me suggestions about how to proceed with my own solution. Thx

  • @manus7342
    @manus7342 Před 4 lety +3

    Absolute Gold. Thank you sir !!

  • @yihongliu3850
    @yihongliu3850 Před 3 lety +4

    Thanks! I am aware of the process but didn't implement it successfully, probably due to the -1 for boundary. The implementation logic is pretty smooth.

  • @RK-xl2uq
    @RK-xl2uq Před 4 lety +1

    what tool/device you use to make this video? looks good

  • @divyamrakesh2039
    @divyamrakesh2039 Před 4 lety +7

    use index =(k-1)/fact[n-1] to get rid of the boundary case

  • @VishalKumar-nz6mz
    @VishalKumar-nz6mz Před 4 lety

    Please tell the name of software that you used for code explanation

  • @Vendettaaaa666
    @Vendettaaaa666 Před 3 lety

    TECH DOSE, Can you do a video on "Next permutation sequence", I think it's along the same lines as this problem

  • @hoyinli7462
    @hoyinli7462 Před 2 lety +1

    the clearest explanation ive ever seen for this question. love u.

  • @pavanvutukuri8130
    @pavanvutukuri8130 Před 4 lety +4

    If index is re-written as "index = (k-1)/(n-1)!".. you can avoid extra checks for boundary values of k.

  • @debanjanchanda7205
    @debanjanchanda7205 Před 4 lety +2

    Good explanation! One trick to handle the boundary case is doing "INDEX = (k - 1)/(n - 1)!" instead, then you don't need to explicitly check for the boundary condition :)

  • @ahsanamin3818
    @ahsanamin3818 Před 3 lety

    this tutorial is very helpful.
    but i am facing some issues.
    ..
    when the digit is [0 - 9]
    and the k = 1000000.
    the index value i got is 27.
    but our digits are 1 - 10.
    ..
    can you please explain me ?

  • @subham-raj
    @subham-raj Před 4 lety +6

    I'm not that good with maths but I'm glad that I was able to solve this problem on my own :) Tho my code was messy.
    Just came here for better code

    • @techdose4u
      @techdose4u  Před 4 lety +1

      I was stuck in the index-- part when it will be a multiple of block size. Took too much time in that boundary case :(

    • @subham-raj
      @subham-raj Před 4 lety

      @@techdose4u I missed one corner case too.

    • @maythecodesbewithyou29
      @maythecodesbewithyou29 Před 4 lety

      I have a more simpler solution using stl

    • @subham-raj
      @subham-raj Před 4 lety

      @@maythecodesbewithyou29 Can't use that in your interviews tho.

  • @medazzouzi2649
    @medazzouzi2649 Před 2 lety

    how to get the kth permutation of the repeated letters ?

  • @harshitdubey3323
    @harshitdubey3323 Před 3 lety

    sir can you make video on valid permutations of DI sequence leetcode (dp,hard)

  • @ghoshdipan
    @ghoshdipan Před 3 lety

    Can someone provide the solution of the brute force algo

  • @AyushiSharmaDSA
    @AyushiSharmaDSA Před 4 lety +3

    Sir, thanks for this video..Helped a lot ...Sir can u tell me the software u use for screen and audio recording..? Thanks :)

  • @ijaz2020
    @ijaz2020 Před 4 lety +7

    this is O(n2) right. since removing a middle element from array itself O(n)

  • @amartyadutta2477
    @amartyadutta2477 Před 4 lety +1

    Thank you,
    Sir, you are the best how do you think such an amazing approach I REALLY WONDER Please sir tell me what are your strengths?

    • @techdose4u
      @techdose4u  Před 4 lety +1

      Keep practicing bro. That's the only key. There is no easy or shortcut way.

  • @ArpitDhamija
    @ArpitDhamija Před 4 lety +1

    can this question will be asked in interview ever, as this is very difficult to understand ...
    I am preparing for internships, does this level of questions are asked in interviews ? please reply....

  • @swaroopas5207
    @swaroopas5207 Před 4 lety +1

    Superb Explanation! But just a request, could you go a little slow in your explanations and dry run, since u keep changing tabs & do the calculations quickly , we loose track. Thanks for these vids!

    • @techdose4u
      @techdose4u  Před 4 lety

      This was a tricky problem and solution parts were separated in tabs. That's why I asked to write on paper and try. You can pause the video and dry run after watching the video once. This way you can cover all parts.

  • @sudharshan3863
    @sudharshan3863 Před 2 lety

    how the number of blocks is 2? [123,132] [231,213] [312,321] so the number of blocks is 3 only ryt?

  • @interviewprep6827
    @interviewprep6827 Před 3 lety +1

    how do u know/find what's the block size??

  • @lostinparadification
    @lostinparadification Před 3 lety +1

    Genius!

  • @sadiarahman467
    @sadiarahman467 Před 3 lety +1

    Thanks a lot

  • @danielaviv8215
    @danielaviv8215 Před 2 lety

    in case k % (n-1)! == 0, you dont need a special statement for this.
    index can be calculate by (k-1) / (n-1)!

  • @prashantverma3347
    @prashantverma3347 Před 3 lety +1

    thank you

  • @saranyavivekanandan9044
    @saranyavivekanandan9044 Před 3 lety +1

    Please make videos on subsets I and subsets II sir.

  • @shanugarg8428
    @shanugarg8428 Před 3 lety

    This problem would be complex if characters/numbers could repeat.

  • @akshatjain6854
    @akshatjain6854 Před 4 lety +1

    Good tutorial bro but how can someone come up with this soln in a 30 min interview given that he have never seen such type of problem before

    • @techdose4u
      @techdose4u  Před 4 lety +2

      If you are asked and you can give the ideas about block access then you will pass. You don't have to cover the boundary cases or give the exact formula. Generally DS & algo based questions are asked and not math based. This comes in CP generally.

    • @akshatjain6854
      @akshatjain6854 Před 4 lety +1

      @@techdose4u yes you are right

  • @amanrai8010
    @amanrai8010 Před 3 lety +1

    Bhiya do these type of mathmetical question are asked

    • @techdose4u
      @techdose4u  Před 3 lety

      It is not asked but may come in coding round.

  • @shubhammundra5034
    @shubhammundra5034 Před 3 lety +2

    Out Of My Syllabus!

  • @agileprogramming7463
    @agileprogramming7463 Před 4 lety +1

    June challenge is very tough

    • @techdose4u
      @techdose4u  Před 4 lety +1

      Good for learning :) I hope they will close the challenges. That's why they are ending it with tougher problems :)

  • @fanigo138
    @fanigo138 Před 3 lety

    it should be fact[n-2].

  • @ayushgarg5929
    @ayushgarg5929 Před 4 lety

    5/2+1 is wrong rather it should have been (5+1)/2

  • @anitasrivastava983
    @anitasrivastava983 Před 4 lety +4

    Don't you sleep bhaiya?

    • @techdose4u
      @techdose4u  Před 4 lety +1

      Gna sleep now. This daily videos are making me sick 😅 Just 10 more days :)
      EDIT: This goes for you too 😂

    • @anitasrivastava983
      @anitasrivastava983 Před 4 lety +1

      Yeah these daily videos are making me sick as well , have to wake up till it's posted 😂

    • @techdose4u
      @techdose4u  Před 4 lety

      I thought you wokeup just now 😂

    • @anitasrivastava983
      @anitasrivastava983 Před 4 lety

      It's the other way around 😂

    • @shishpalvishnoi7974
      @shishpalvishnoi7974 Před 4 lety +1

      @@techdose4u
      Tech Dose: Just 10 more days!!!
      July Challenge: I am coming 😂😂😂

  • @willturner3440
    @willturner3440 Před 3 lety +1

    Applying backtracking in this is waste of time 😛

  • @ajaychauhan-lu6yy
    @ajaychauhan-lu6yy Před 4 lety +1

    you change your tabs alot...kindly avoid that as it creates disturbance

    • @techdose4u
      @techdose4u  Před 4 lety +1

      You mean the video cuts? I try to reduce redundancy in explanation.

    • @ajaychauhan-lu6yy
      @ajaychauhan-lu6yy Před 4 lety +1

      @@techdose4u NO, i mean while explaining the concept you change the slides a lot of times...this makes a lot difficult to understand the concept..Like in this slide you were going back and forth a lot of times...please avoid it