Skip to main content

Posts

Showing posts from March, 2026

26. Remove Duplicates from Sorted Array : Leetcode

  26. Remove Duplicates from Sorted Array Easy Given an integer array  nums  sorted in  non-decreasing order , remove the duplicates  in-place  such that each unique element appears only  once . The  relative order  of the elements should be kept the  same . Consider the number of  unique elements  in  nums  to be  k ​​​​​​​ ​​​​​​​. After removing duplicates, return the number of unique elements  k . The first  k  elements of  nums  should contain the unique numbers in  sorted order . The remaining elements beyond index  k - 1  can be ignored. Custom Judge: The judge will test your solution with the following code: int[] nums = [...]; // Input array int[] expectedNums = [...]; // The expected answer with correct length int k = removeDuplicates(nums); // Calls your implementation assert k == expectedNums.length; for (int i = 0; i < k; i++) { assert nums[i] == ...

1984. Minimum Difference Between Highest and Lowest of K Scores

  1984. Minimum Difference Between Highest and Lowest of K Scores Easy You are given a  0-indexed  integer array  nums , where  nums[i]  represents the score of the  i th  student. You are also given an integer  k . Pick the scores of any  k  students from the array so that the  difference  between the  highest  and the  lowest  of the  k  scores is  minimized . Return  the  minimum  possible difference . Example 1: Input: nums = [90], k = 1 Output: 0 Explanation: There is one way to pick score(s) of one student: - [ 90 ]. The difference between the highest and lowest score is 90 - 90 = 0. The minimum possible difference is 0. Example 2: Input: nums = [9,4,1,7], k = 2 Output: 2 Explanation: There are six ways to pick score(s) of two students: - [ 9 , 4 ,1,7]. The difference between the highest and lowest score is 9 - 4 = 5. - [ 9 ,4, 1 ,7]. The difference between the ...