Solve Leetcode Problems and Get Offers From Your Dream Companies
Leetcode 442: Find All Duplicates in an Array
In this series, I am going to solve Leetcode medium problems live with my friends, which you can see on our youtube channel, Today we will do Problem Leetcode 442: Find All Duplicates in an Array.
A little bit about me, I have offers from Uber India and Amazon India in the past, and I am currently working for Booking.com in Amsterdam.
Motivation to learn algorithms
Problem Statement
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of the array), some elements appear twice and others appear once.
Find all the elements that appear twice in this array.
Could you do it without extra space and in O(n) runtime?
Example:
Input:
[4,3,2,7,8,2,3,1]Output:
[2,3]