Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding
Ninjas X Naukri.com

Problem of the day

You are given a sorted integer array * 'arr'* of size

You need to remove the duplicates from the array such that each element appears only once.

Return the length of this new array.

```
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.
```

```
'n' = 5, 'arr' = [1 2 2 2 3].
The new array will be [1 2 3].
So our answer is 3.
```

Detailed explanation

```
10
1 2 2 3 3 3 4 4 5 5
```

```
5
```

```
The new array will be [1 2 3 4 5].
So our answer is 5.
```

```
9
1 1 2 3 3 4 5 5 5
```

```
5
```

```
The expected time complexity is O(n).
```

```
1 <= 'n' <= 10^6
-10^9 <= 'arr[i]' <=10^9
Where ‘arr[i]’ is the value of elements of the array.
Time limit: 1 sec
```