Geeksforgeeks

Timer is Running

Given a set of numbers from 1 to N, each number is exactly present twice so there are N pairs. In the worst-case scenario, how many numbers X should be picked and removed from the set until we find a matching pair?

**Example 1:**

**Input:**
N = 1
**Output:**
2
**Explanation:**
When N=1 Then there is
one pair and a matching
pair can be extracted in
2 Draws.

**Example 2:**

**Input:**
N = 2
**Output:**
3
**Explanation:**
When N=2 then there are
2 pairs, let them be {1,2,1,2}
and a matching pair will
be made in 3 draws.

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function **find()** which takes an integer **N** as input parameter and returns an integer, the number of x must be picked and removed from set to find a matching pair.

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

**Expected Space Complexity:** O(1)

**Constraints:**

0 <= N <= 10^{5}

Author: sd5869

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Pathak1899 | 436 |

yashdip123 | 380 |

kirtidee18 | 377 |

ykaushik | 261 |

_saswata | 232 |

kirtidee18 | 1057 |

ykaushik | 733 |

aggarwalvatsal5 | 709 |

pmr_3689 | 570 |

harbilassingh | 530 |

blackshadows | 5456 |

Ibrahim Nash | 5450 |

akhayrutdinov | 5111 |

mb1973 | 4976 |

Quandray | 4823 |

Login to report an issue on this page.