Data Structures & Algorithms
100+ curated problems from top tech interviews
100+ curated problems from top tech interviews
32 problems found
Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands. An island is surrounded by wa...
Design a data structure that follows the constraints of a Least Recently Used (LRU) cache. Implement the LRUCache class with get and put operations in...
Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals...
The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other. Given an integer n, return al...
Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order....
Given an integer array nums of unique elements, return all possible subsets (the power set). The solution set must not contain duplicate subsets....
A transformation sequence from beginWord to endWord using dictionary wordList is a sequence where every adjacent pair of words differs by a single let...
There are a total of numCourses courses you have to take. Some courses may have prerequisites. Given the total number of courses and a list of prerequ...
Given the root of a binary tree, invert the tree, and return its root....
Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists...
There is an integer array nums sorted in ascending order (with distinct values). Prior to being passed to your function, nums is possibly rotated at a...
Given a binary search tree (BST), find the lowest common ancestor (LCA) node of two given nodes in the BST....
A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. The path sum of a path i...
You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb ...
Given an integer array nums, return the length of the longest strictly increasing subsequence....
Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary wor...
You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return ...
Given two strings word1 and word2, return the minimum number of operations required to convert word1 to word2. You have the following three operations...
A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the ...
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, hei...
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining....
Given a string s, find the length of the longest substring without repeating characters....
Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in t (including duplicat...
You are given an array of integers nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You ca...
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]...
Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct....
Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i]. You must w...
Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order....
Given an array of strings strs, group the anagrams together. You can return the answer in any order....
Given two strings s and t, return true if t is an anagram of s, and false otherwise. An Anagram is a word or phrase formed by rearranging the letters ...
Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence. You must write an algorithm that runs in O(n...
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each inp...