Given an m x n 2d grid map of '1's (land) and '0's (water), return the number of islands. An island is surrounded by water and is formed by connecting...
Given a rows x cols matrix grid representing a field of cherries. Each cell in grid represents the number of cherries that you can collect. You have two robots that can collect cherries for...
You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return the fewest number of coins that you...
Given a complete binary tree, count the number of nodes. Note: Definition of a complete binary tree from Wikipedia: In a complete binary tree every level, except possibly the last,...
Given an array of integers. Count the number of subsets whose difference between pair of subsets is equals to given difference. Example 1: int[] a = {1,1,2,3} difference = 1...
There are a total of n courses you have to take labelled from 0 to n - 1. Some courses may have prerequisites, for example, if prerequisites[i] = [ai, bi] this means...
Given a list paths of directory info, including the directory path, and all the files with contents in this directory, return all the duplicate files in the file system in...
You are given a list of lists edges representing an undirected graph. Each list contains (u, v) which means there is an undirected edge between nodes u and v. Return...
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example 1: Input: n = 3 Output: ["((()))","(()())","(())()","()(())","()()()"] Example 2: Input: n = 1 Output:...
Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0. A subsequence of a string is a new...
Given two integer arrays nums1 and nums2, return the maximum length of a subarray that appears in both arrays. Example 1: Input: nums1 = [1,2,3,2,1], nums2 = [3,2,1,4,7] Output: 3...
Given a string s, find the length of the longest substring without repeating characters. Example 1: Input: s = "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length...
Given a string s, return the length of the longest substring that contains at most two distinct characters. Example 1: Input: s = "eceba" Output: 3 Explanation: The substring is...
Given an array of meeting time intervals intervals where intervals[i] = [starti, endi], return the minimum number of conference rooms required. Example 1: Input: intervals = [[0,30],[5,10],[15,20]] Output: 2 Example...
Given a set of integers, the task is to divide it into two sets S1 and S2 such that the absolute difference between their sums is minimum. If there is...
Given a string s, return all the palindromic permutations (without duplicates) of it. You may return the answer in any order. If s has no palindromic permutation, return an empty...
Given a non-empty array nums containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal....
Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it...
Given an integer array nums, design an algorithm to randomly shuffle the array. All permutations of the array should be equally likely as a result of the shuffling. Implement the...
Given a set of non-negative integers, and a value sum, determine if there is a subset of the given set with sum equal to given target sum. Example: Input: set[]...
You are given an integer array nums and an integer target. You want to build an expression out of nums by adding one of the symbols '+' and '-' before...
Given an integer n, return the number of structurally unique BST's (binary search trees) which has exactly n nodes of unique values from 1 to n. Example 1: Input:...
A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> ... -> sk such that: Every...
Given an m x n grid of characters board and a string word, return true if word exists in the grid. The word can be constructed from letters of sequentially...