Skip to main content
Intermediatecoding Verified

In a sorted array where every element appears exactly twice except one, find the single element in O(log n) time.

ReportedSource: GeeksforGeeks interview experience: Amazon SDE-1 off-campus

Quick answerFree

Pairs start at even indices before the single element and at odd indices after it. Binary search on even mids: if nums[mid]==nums[mid+1] go right, else go left. O(log n).

Detailed answer· 92 words

Interview Prep

Unlock the full answer with Interview Prep

Get a 92-word model answer and a runnable reference solution, plus 61 more DSA questions.

Also in Pro (₹499 / 90 days).

Reference solution· runs in the browser sandbox

Interview Prep
Unlock with Interview Prep

+ 61 more DSA questions in Interview Prep, each with the full answer.

Discussion