Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Find Duplicate in Sorted Array

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Find Duplicate in Sorted Array. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Given a sorted array of integers nums where every value appears exactly twice except for one value that appears once, return the value that appears only once. The function should take a list of integers and return a single integer. Solve it in O(log n) time.

Constraints

  • 1 <= len(nums) <= 10^5
  • len(nums) is odd
  • -10^5 <= nums[i] <= 10^5
  • nums is sorted in non-decreasing order
  • Every element appears exactly twice except one element, which appears once

Function Signature

def single_non_duplicate(nums):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output