Geeksforgeeks

Error

×

Leaderboard

Showing:

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

@Ibrahim Nash | 6379 |

@blackshadows | 6329 |

@mb1973 | 5358 |

@Quandray | 5231 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4510 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3357 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@ritiksethi21 | 1050 |

@aroranayan999 | 807 |

@RizulBansal | 685 |

@ashishtrehan002 | 538 |

@hemantgarg923 | 528 |

@simrangoyal | 526 |

@ronaldo77 | 520 |

@anishrajan | 505 |

@thanosagain | 505 |

@ssparteek470 | 495 |

@rahul2312 | 491 |

Complete Leaderboard |

Given an array **arr **of size **N**, the goal is to find out the smallest number that is repeated exactly ‘**K**’ times.

**Example 1:**

**Input:**
N=5, K=2
arr[] = { 2 2 1 3 1 }
**Output:** 1
**Explanation**: Here in array,
2 is repeated 2 times, 1 is repeated
2 times, 3 is repeated 1 time.
Hence 2 and 1 both are repeated 'k'
times i.e 2 and min(2, 1) is 1 .

**Example 2:**

**Input:
**N=4, K=1
arr[] = { 3 5 3 2 }
**Output:** 2
**Explanation: **Both 2 and 5 are repeating 1
time but min(5, 2) is 2.

**Your Task:**

You just need to complete the function **findDuplicate**() that takes **array arr, integer N and integer K** as parameters and **returns** the required answer.

**Note-** If there is no such element then return **-1**.

**Expected Time Complexity:** O(N)

**Expected Auxiliary Space:** O(MAX). where MAX is maximum element in the array.

**Constraints:**

1 ≤ N ≤ 10^{5}

1 ≤ arr[i] ≤ 10^{5}

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
Smallest number repeating K times

...