Timer is Running

Matching Pair
Submissions: 86   Accuracy:

74.4%

  Difficulty: Basic   Marks: 1

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 <= 105

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Siddharth Dungarwal
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.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.