Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5725 |

@blackshadows | 5685 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4908 |

@saiujwal13083 | 4156 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3511 |

@sushant_a | 3453 |

@KshamaGupta | 3318 |

@the_coder95 | 3302 |

Complete Leaderboard | |

Handle | Score |

@shashi1iitk | 398 |

@Suniti Jain | 114 |

@ankish2000nayak | 104 |

@gopalsethlnct | 94 |

@senthil1185 | 90 |

@esmadhan | 90 |

@gyanadipta07 | 89 |

@satwikdash2000 | 85 |

@varunmishra3040 | 83 |

@gamec1634 | 82 |

@pj_1721 | 80 |

Complete Leaderboard |

Given an array a[] of size N which contains elements from 0 to N-1, you need to find all the elements occurring more than once in the given array.

**Example 1:**

**Input:
**N = 4
a[] = {0,3,1,2}
**Output: **-1**
Explanation: **N=4 and all elements from 0
to (N-1 = 3) are present in the given
array. Therefore output is -1.

**Example 2:**

**Input:
**N = 5
a[] = {2,3,1,2,3}
**Output: **2 3 **
Explanation: **2 and 3 occur more than once
in the given array.

**Your Task:**

Complete the function **duplicates()** which takes array a[] and n as input as parameters and returns a list of elements that occur more than once in the given array in sorted manner. If no such element is found return -1.

**Expected Time Complexity:** O(n).

**Expected Auxiliary Space:** O(n).

Note : The extra space is only for the array to be returned.

Try and perform all operation withing the provided array.

**Constraints:**

1 <= N <= 10^{5}

0 <= A[i] <= N-1, for each valid i

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Find duplicates in an array

...

Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.