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].
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.
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 😥
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});
Thanks a lot ☺️
Sorting will take you O(nlogn). You just need the 4 smallest and 4 largest elements which can be done in O(n)
Actually if you sort , you will be able to make the solution generalised for k which is 3 in this question.
@@mohammadfraz question is for 3 moves, so o(n) is faster
i go crazy figuring the solution, thanks
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].
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.
you dont have to sort the whole array. you can do it in O(n)
Great Explanation !!!!
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 😥
Thankyou bhaiya for this video
😉thanks
Hi , sup 😄.
Nice video!
Worst Video ever ..where is the intuition ? Just explaining the solution doesn't helps lol !