26. Remove Duplicates from Sorted Array

My Submissions
Total Accepted: 122944 Total Submissions: 369407 Difficulty: Easy

Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.

Do not allocate extra space for another array, you must do this in place with constant memory.

For example,
Given input array nums = [1,1,2],

Your function should return length = 2, with the first two elements of nums being 1 and 2 respectively. It doesn't matter what you leave beyond the new length.

Subscribe to see which companies asked this question

Show Tags
Array Two Pointers
Show Similar Problems
(E) Remove Element
Have you met this question in a real interview?
Yes
No
When did you meet this question?
1 week ago
1 month ago
3 months ago
6 months ago
More than 6 months ago
How long have you been interviewing?
Not yet started
1 month
3 months
6 months
More than 6 months
Which company asked you this question?
Adobe
Airbnb
Alation
Alibaba
Amazon
Apple
Arista
Baidu
Blend Labs
Blizzard
Bloomberg
Box
Bungie
Cisco
Conviva
Coursera
CreditEase
Deutsche Bank
Dropbox
eBay
Electronic Arts
EMC
Epic Systems
Expedia
Facebook
Flipkart
Fortinet
FreeWheel
Goldman Sachs
Google
GrabTaxi
Groupon
Hedvig
Hulu
Intel
Jane Street
JPMorgan
Jump Trading
Lending Club
LinkedIn
LiveRamp
Marvel
Matlab
McKesson
Microsoft
Morgan Stanley
Nvidia
Oracle
Orbitz
Palantir
Paypal
Pinterest
Pocket Gems
Qualtrics
Qumulo
Quora
Rackspace
Salesforce
Sina
Snapchat
Square
Sumologic
Symantec
Tencent
TinyCo
Tradeshift
TripAdvisor
Twitter
Two Sigma
Uber
VMware
Walmart
Yahoo!
Yandex
Yelp
Zenefits
Zynga

Discuss


Send Feedback