FastPrepRemove Duplicates From Sorted Array In Place
Problems/Remove Duplicates From Sorted Array In Place

Remove Duplicates From Sorted Array In Place

Kotak Mahindra Bank logoKotak Mahindra Bank● EasyFULLTIMEPHONE SCREENONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The reported task identifies this algorithmic exercise. The callable interface, bounds, deterministic rules, and examples are the documented practice contract.

You are given an integer array nums sorted in nondecreasing order. Modify it in place so that each distinct value appears exactly once and the retained values stay in sorted order.

Return an array containing exactly the compacted prefix. Extra capacity after that prefix may be left unchanged.

Function

removeDuplicates(nums: int[]) → int[]

Examples

Example 1

nums = [1,1,2]return = [1,2]

The sorted values are 1, 1, and 2. After in-place compaction the unique prefix is [1,2].

Example 2

nums = [0,0,1,1,1,2,2,3,3,4]return = [0,1,2,3,4]

Adjacent duplicates are overwritten so each retained value appears once. The compacted prefix is [0,1,2,3,4].

Example 3

nums = []return = []

An empty array has no values to retain, so the compacted prefix is empty.

Constraints

  • 0 <= nums.length <= 10^5.
  • -10^9 <= nums[i] <= 10^9.
  • nums is sorted in nondecreasing order.

Source note: Author-written prompt excerpt retained for source fidelity.

More Kotak Mahindra Bank problems

  • Best Time to Buy and Sell StockONSITE INTERVIEW · Seen Nov 2026
  • Best Time to Buy and Sell Stock IIONSITE INTERVIEW · Seen Nov 2026
  • Maximum Non-Adjacent Coins in Two RowsONSITE INTERVIEW · Seen Oct 2026
All Kotak Mahindra Bank interview questionsSee Kotak Mahindra Bank hiring insights
Saved
class Solution {
    public int[] removeDuplicates(int[] nums) {
      // Write your code here.
    }
}
Checking account…