Problems
Practice coding problems to improve your skills and prepare for interviews.
1. Two Sum
Easy
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
Array
Hash Table
2. Valid Parentheses
Easy
Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
String
Stack
3. Merge Two Sorted Lists
Easy
You are given the heads of two sorted linked lists list1 and list2.
Array
Sorting
4. Merge Sorted Array
Easy
You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively.
Array
Two Pointers
Sorting
5. Remove Element
Easy
Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The order of the elements may be changed. Then return the number of elements in nums which are not equal to val.
Array
Two Pointers
6. Remove Duplicates from Sorted Array
Easy
Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same. Then return the number of unique elements in nums.
Array
Two Pointers
7. Remove Duplicates from Sorted Array II
Medium
Given an integer array nums sorted in non-decreasing order, remove some duplicates in-place such that each unique element appears at most twice. The relative order of the elements should be kept the same.
Array
Two Pointers
8. Majority Element
Easy
Given an array nums of size n, return the majority element.
Array
Hash Table
Divide and Conquer
Sorting
Counting
9. Rotate Array
Medium
Given an integer array nums, rotate the array to the right by k steps, where k is non-negative.
Array
Math
Two Pointers
10. Best Time to Buy and Sell Stock
Easy
You are given an array prices where prices[i] is the price of a given stock on the ith day.
Array
Dynamic Programming
11. Best Time to Buy and Sell Stock II
Medium
You are given an integer array prices where prices[i] is the price of a given stock on the ith day.
Array
Dynamic Programming
Greedy
12. Valid Palindrome
Easy
A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.
Two Pointers
String
13. Is Subsequence
Easy
Given two strings s and t, return true if s is a subsequence of t, or false otherwise.
Two Pointers
String
Dynamic Programming
14. Container With Most Water
Medium
You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]).
Array
Two Pointers
Greedy
15. 3Sum
Medium
Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.
Array
Two Pointers
Sorting