1509. Minimum Difference Between Largest and Smallest Value in Three Moves

Поділитися
Вставка
  • Опубліковано 26 сер 2024

КОМЕНТАРІ • 16

  • @pjac744
    @pjac744 4 роки тому +4

    Great explanation. Just a suggestion. You can cascade any number of arguments to the min/max function in this way
    a = min({op1,op2,op3,op4});

  • @bhaskargurram94
    @bhaskargurram94 4 роки тому +3

    Sorting will take you O(nlogn). You just need the 4 smallest and 4 largest elements which can be done in O(n)

    • @mohammadfraz
      @mohammadfraz  4 роки тому

      Actually if you sort , you will be able to make the solution generalised for k which is 3 in this question.

    • @kumarc4853
      @kumarc4853 3 роки тому

      @@mohammadfraz question is for 3 moves, so o(n) is faster

  • @pisanghangus2
    @pisanghangus2 3 роки тому +1

    i go crazy figuring the solution, thanks

  • @shantanukumar4081
    @shantanukumar4081 2 роки тому +1

    Great Explanation !!!!

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

    I am confused on why you can sort the array. I thought you can only change an element within one move of itself, so I could only change nums[i] to either nums[i-1] or nums[i+1].

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

      I guess that leads me to wonder what is exactly defined as a move because my understanding must not be right. If my understanding were right, we wouldn't be able to sort the array in the problem.

  • @nos44-
    @nos44- 4 роки тому +3

    everything was fine,... even i solved the problem , the same way and it got accepted..... until i saw TM Williams solution 😭... he did it in just a single loop .... and a single statement 😥

  • @yuzhao5268
    @yuzhao5268 3 роки тому

    you dont have to sort the whole array. you can do it in O(n)

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

    Thankyou bhaiya for this video

  • @a-gamephile5613
    @a-gamephile5613 4 роки тому

    Nice video!

  • @code7434
    @code7434 4 роки тому +1

    😉thanks

  • @techwech8265
    @techwech8265 Місяць тому +1

    Worst Video ever ..where is the intuition ? Just explaining the solution doesn't helps lol !