leetcode.com

Single Element in a Sorted Array (opens in new tab)

Discussed on DEV

leetcode.com Problem Statement Given a sorted array where: Every element appears exactly twice. Only one element appears once. Find the single element in O(log N) time and O(1) space. Brute Force Intuition In an interview, you can explain it like this: Since every element appears twice except one, we can iterate through the array and count frequencies. The element with frequency 1 is our answer. This works but doesn't utilize the sorted nature of the array. Complexity Time Complexity: O(N) Sp...

Read the original article
Sign in to keep reading the full article.

Keyboard Shortcuts

Navigation

Next / previous post
j/k
Open post
oorEnter
Preview post
v

Post Actions

Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Save / unsave
s

Recommendations

Add interest / feed
Enter
Not interested
x

Go to

Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Discover
gb
Search
/

General

Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help