Unique Element In Sorted Array

Nobita wants to impress Shizuka by correctly guessing her lucky number. Shizuka provides a sorted list where every number appears twice, except for her lucky number, which appears only once. Your task is to find this unique lucky number for Nobita.

Example:

Input:
T = 2
N = 7
list = [1, 1, 2, 2, 3, 4, 4]
N = 5
list = [5, 5, 7, 8, 8]
Output:
3
7
Explanation:

For the first test case, the number 3 appears only once in the list, whereas others appear twice. Similarly, for the second test case, the number 7 is the lucky number.

Constraints:

  • 1 <= T <= 5
  • 1 <= N <= 105
  • 0 <= data <= 109 where ‘data’ is the value of elements in Shizuka’s list.
  • Time Limit: 1 sec
Note:
You do not need to print anything; the output should be returned by implementing the function provided.
AnswerBot
4mo

Find the unique element in a sorted array where all other elements appear twice.

  • Iterate through the array and XOR all elements to find the unique element.

  • Use a hash set to keep track of elements and f...read more

Help your peers!
Select
Add answer anonymously...

MAQ Software Software Engineer interview questions & answers

A Software Engineer was asked 11mo agoQ. Given a singly linked list, reverse the nodes of the linked list k at a time and...read more
A Software Engineer was asked 12mo agoQ. How does hashing help in identifying duplicate values?
A Software Engineer was asked Q. Given an array, reverse the order of its elements.

Popular interview questions of Software Engineer

A Software Engineer was asked 10mo agoQ1. Given a singly linked list, reverse the nodes of the linked list k at a time and...read more
A Software Engineer was asked 11mo agoQ2. How does hashing help in identifying duplicate values?
A Software Engineer was asked Q3. Given an array, reverse the order of its elements.
MAQ Software Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits