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.
Solve
Array
Hash Table
Acceptance: 85%
2. Valid Parentheses
Easy
Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
Solve
String
Stack
Acceptance: 78%
3. Merge Two Sorted Lists
Easy
You are given the heads of two sorted linked lists list1 and list2.
Solve
Array
Sorting
Acceptance: 72%
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.
Solve
Array
Two Pointers
Sorting
Acceptance: 92%
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.
Solve
Array
Two Pointers
Acceptance: 89%
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.
Solve
Array
Two Pointers
Acceptance: 88%
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.
Solve
Array
Two Pointers
Acceptance: 76%
8. Majority Element
Easy
Given an array nums of size n, return the majority element.
Solve
Array
Hash Table
Divide and Conquer
Sorting
Counting
Acceptance: 84%
9. Rotate Array
Medium
Given an integer array nums, rotate the array to the right by k steps, where k is non-negative.
Solve
Array
Math
Two Pointers
Acceptance: 73%
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.
Solve
Array
Dynamic Programming
Acceptance: 78%
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.
Solve
Array
Dynamic Programming
Greedy
Acceptance: 71%
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.
Solve
Two Pointers
String
Acceptance: 82%
13. Is Subsequence
Easy
Given two strings s and t, return true if s is a subsequence of t, or false otherwise.
Solve
Two Pointers
String
Dynamic Programming
Acceptance: 85%
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]).
Solve
Array
Two Pointers
Greedy
Acceptance: 76%
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.
Solve
Array
Two Pointers
Sorting
Acceptance: 68%