FastPrepSingle Element in a Sorted Array
Problems/Single Element in a Sorted Array

Single Element in a Sorted Array

Amazon logoAmazon● MediumFULLTIMEPHONE SCREENONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report specifies a sorted array, one single-occurring value, and an optimal binary-search solution. It omits the multiplicity of the other values and the return contract, so this exercise uses the conventional paired-values form.

Given a sorted integer array nums, every value appears exactly twice except for one value that appears exactly once.

Return the value that appears once. Your solution must run in O(log n) time and use O(1) extra space.

Function

singleNonDuplicate(nums: int[]) → int

Examples

Example 1

nums = [1,1,2,3,3,4,4]return = 2

Every value except 2 belongs to an adjacent pair.

Example 2

nums = [0]return = 0

The only element is the unique value.

Constraints

  • 1 <= nums.length <= 100000
  • nums.length is odd.
  • -2147483648 <= nums[i] <= 2147483647
  • nums is sorted in nondecreasing order.
  • Exactly one value appears once; every other value appears exactly twice.

Source note: Source images are source-neutral excerpts of author-reported interview prompts.

More Amazon problems

  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
See Amazon hiring insights
Saved
class Solution {
    public int singleNonDuplicate(int[] nums) {
        // Write your code here
    }
}
Checking account…