Remove Duplicates from Sorted Array Problem Statement

You are given a sorted integer array ARR of size N. Your task is to remove the duplicates in such a way that each element appears only once. The output should be the length of the array after removal of duplicates.

Example:

Input:
T = 1, N = 5, ARR = [1, 1, 2, 2, 3]
Output:
3
Explanation:

The array after removing duplicates becomes [1, 2, 3], thus the length is 3.

Constraints:

  • 1 <= T <= 5
  • 1 <= N <= 105
  • -109 <= ARR[i] <= 109
  • Time limit: 1 sec

Note:

 - Do not allocate extra space for another array. Perform the operation in-place with O(1) extra memory. 
AnswerBot
1y

The task is to remove duplicates from a sorted integer array in-place and return the length of the modified array.

  • Use two pointers, one for iterating through the array and another for keeping track of...read more

Help your peers!
Add answer anonymously...
Newgen Software Technologies Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter