Leetcode Problem 1509. Minimum Difference Between Largest and Smallest Value in Three Moves
1509. Minimum Difference Between Largest and Smallest Value in Three Moves
AI Mock Interview
Leetcode Solutions
Sort and Compare Extremes
Solution Idea
Algorithm Steps
Code Implementation
Complexity Analysis
If the length of the array is less than or equal to 4, return 0 because we can make all elements equal.
Sort the array in ascending order.
Calculate the difference between the fourth largest element and the smallest element.
Calculate the difference between the largest element and the fourth smallest element.
Calculate the difference between the third largest element and the second smallest element.
Calculate the difference between the second largest element and the third smallest element.
Return the minimum of the four calculated differences.
Partial Sorting and Heap
Ask Question
Programming Language
Purpose:
General Question
Debug My Code
image/screenshot of info
(optional)
[+]
Full Screen
Loading...
Get Answer
Suggested Answer
Answer
Full Screen
Copy Answer Code
Loading...