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

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 ธ.ค. 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

  • @MrFrazerz
    @MrFrazerz 3 ปีที่แล้ว

    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 3 ปีที่แล้ว

      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.

  • @yuzhao5268
    @yuzhao5268 3 ปีที่แล้ว

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

  • @shantanukumar4081
    @shantanukumar4081 2 ปีที่แล้ว +1

    Great Explanation !!!!

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

  • @ratnasanjay
    @ratnasanjay 2 ปีที่แล้ว

    Thankyou bhaiya for this video

  • @code7434
    @code7434 4 ปีที่แล้ว +1

    😉thanks

  • @a-gamephile5613
    @a-gamephile5613 4 ปีที่แล้ว

    Nice video!

  • @techwech8265
    @techwech8265 5 หลายเดือนก่อน +2

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