Geeksforgeeks

Error

×

Leaderboard

Showing:

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

@Ibrahim Nash | 5765 |

@blackshadows | 5715 |

@akhayrutdinov | 5111 |

@mb1973 | 4993 |

@Quandray | 4944 |

@saiujwal13083 | 4506 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3516 |

@sushant_a | 3459 |

@verma_ji | 3341 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@aroranayan999 | 1286 |

@bt8816103042 | 739 |

@rohitanand | 495 |

@codeantik | 479 |

@shalinibhataniya1097 | 472 |

@amrutakashikar2 | 464 |

@thealchemist627 | 456 |

@akashkale117 | 453 |

@shivanandp12345678910 | 453 |

@dalwainazism125 | 453 |

@SherlockHolmes3 | 447 |

Complete Leaderboard |

Given a sorted array **A[]** of **N **positive integers having all the numbers occurring exactly twice, except for one number which will occur only once. Find the number occurring only once.

**Example 1:**

**Input:
**N = 5
A = {1, 1, 2, 5, 5}**
Output: **2
**Explanation:
**Since 2 occurs once, while
other numbers occur twice,
2 is the answer.

**Example 2:**

**Input:
**N = 7
A = {2, 2, 5, 5, 20, 30, 30}
**Output: **20
**Explanation:
**Since 20 occurs once, while
other numbers occur twice,
20 is the answer.

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function **search() **which takes two arguments(array A and integer N) and returns the number occurring only once.

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

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

**Constraints**

0 < **N** <= 10^6

0 <= **A[i]** <= 10^9

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
Element appearing once

...