Minimum Swaps to Sort | Problem of the Day 6 Feb 2022 | Siddharth Hazara | GeeksforGeeks Practice

Поділитися
Вставка
  • Опубліковано 9 лют 2025

КОМЕНТАРІ • 8

  • @kartikdwivedi5035
    @kartikdwivedi5035 2 роки тому +2

    pls make a video on minimum swap to sort in case of duplicate element in string

  • @danalex2991
    @danalex2991 2 роки тому +8

    Horrible Audio

  • @tishajain397
    @tishajain397 Рік тому +2

    What's the time and space complexity of this code

  • @KiranKumar-cn7pm
    @KiranKumar-cn7pm 3 роки тому +2

    what is i - - is for?

    • @abhigyanraha5620
      @abhigyanraha5620 2 роки тому +6

      I dont know if you have figured it out or not. But just in case you haven't:
      When we swap 2 elements, the i increases to the next element (i + 1) and in some cases the ith element is still not in the right position and if we move ahead, it will remain in the wrong position, so we keep coming back to that ith element repeatedly until the element is in its right position and once it is, we move ahead without any issues.

    • @yash_______105
      @yash_______105 2 роки тому +2

      U can use while loop instead of that i--

    • @karapureddyjaswanthreddy6053
      @karapureddyjaswanthreddy6053 2 роки тому

      @@yash_______105 yes using while is much clear in that case and it works.

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

      @@abhigyanraha5620 correct, in case the example vector is so complex. In this video, sir has taken a simple one.