Remove Duplicates from Sorted Array
You are given a sorted integer array' ARR' of size 'N'. You need to remove the duplicates from the array such that each element appears only once. Return the length of this new array.
Note:
Do not allocate extra space for another array. You need to do this by modifying the given input array in-place with O(1) extra memory.
Input format:
The first line of input contains an integer ‘T’ denoting the number of test cases.
The first line of each test case contains an integer ‘N’ denoting the number of elements in the array.
The second line of each test case contains ‘N’ space-separated integers representing the elements of the array.
Output format:
For each test case, return the length of the modified array.
Note:
You don't need to print anything, it has already been taken care of. Just Implement the given function.
Constraints :
1 <= T <= 5
1 <= N <= 10^5
-10^9 <= ARR[i] <=10^9
Where ‘ARR[i]’ is the value of elements of the array.
Time limit: 1 sec
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
CodingNinjas
author
2y
First i presented the solution using extra Space (Always Start from a worst time complexity )
Step 1: I take an auxiliary array temp[] to store unique elements.
Step 2:I traversed input array and one by...read more
CodingNinjas
author
2y
Two Pointer
We know that the array is sorted, and hence all the occurrences of a number will be clustered together. Keeping this in mind, we keep two pointers 'i' and ‘j’, where ‘i’ is the slow pointer...read more
Add answer anonymously...
Top Newgen Software Technologies Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Newgen Software Technologies Software Developer
>
Newgen Software Technologies Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
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
Get AmbitionBox app