Articles
-
133 - Clone Graph
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.
-
52 - N-Queens II
Follow up for N-Queens problem. Now, instead outputting board configurations, return the total number of distinct solutions.
-
51 - N-Queens
The n-queens puzzle is the problem of placing n queens on an n by n chessboard such that no two queens attack each other.
-
8 - String to Integer(atoi)
Implement function atoi to convert a string to an integer. If no valid conversion could be performed, a zero value is returned. If the correct value is out of the range of representable values, INT_MAX (2147483647) or INT_MIN (-2147483648) is returned.
-
Nuts & Bolts Problem
Given a set of n nuts of different sizes and n bolts of different sizes. There is a one-one mapping between nuts and bolts. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to see which one is bigger/smaller.
-
89 - Gray Code
The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, find the sequence of gray code. A gray code sequence must begin with 0 and with cover all 2n integers.
-
76 - Minimum Window Substring
Given a string source and a string target, find the minimum window in source which will contain all the characters in target.
-
Matrix Zigzag Traversal
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in ZigZag-order.
-
56 - Merge Intervals
Given a collection of intervals, merge all overlapping intervals.
-
57 - Insert Interval
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were initially sorted according to their start times.
-
268 - Find the Missing Number
Given an array contains N numbers of 0 .. N, find which number doesn’t exist in the array.
-
36 - Valid Sudoku
Determine whether a Sudoku is valid.The Sudoku board could be partially filled, where empty cells are filled with the character ‘.’
-
Heapify
Given an integer array, heapify it into a min-heap array. For a heap array A, A[0] is the root of heap, and for each A[i], A[i * 2 + 1] is the left child of A[i] and A[i * 2 + 2] is the right child of A[i].
-
155 - Min Stack
Implement a stack with min() function, which will return the smallest number in the stack. It should support push, pop and min operation all in O(1) cost.
-
232 - Implement Queue Using Stacks
Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push, peek, pop, and empty).
-
Longest Words
Given a dictionary, find all of the longest words in the dictionary.
-
126 - Word Ladder II
Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from start to end.
-
127 - Word Ladder
Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that: Only one letter can be changed at a time. Each intermediate word must exist in the dictionary.
-
Topological Sorting
Given an directed graph, a topological order of the graph nodes is defined as follow: For each directed edge A -> B in graph, A must before B in the order list. The first node in the order can be any node in the graph with no nodes direct to it. Find any topological order for the given graph.
-
Route Between Two Nodes in Graph
Given a directed graph, design an algorithm to find out whether there is a route between two nodes.
-
Find the Connected Component in the Undirected Graph
Find the number connected component in the undirected graph. Each node in the graph contains a label and a list of its neighbors. (a connected component (or just component) of an undirected graph is a subgraph in which any two vertices are connected to each other by paths, and which is connected to no additional vertices in the supergraph.)
-
Longest Increasing Continuous subsequence II
Give you an integer matrix (with row size n, column size m),find the longest increasing continuous subsequence in this matrix. (The definition of the longest increasing continuous subsequence here can start at any row or column and go up/down/right/left any direction).
-
397 - Longest Increasing Continuous subsequence
Give you an integer array (index from 0 to n-1, where n is the size of this array),find the longest increasing continuous subsequence in this array. (The definition of the longest increasing continuous subsequence here can be from right to left or from left to right)
-
300 - Longest Increasing Subsequence
Given a sequence of integers, find the longest increasing subsequence (LIS). You code should return the length of the LIS.
-
Maximum Subarray III
Given an array of integers and a number k, find k non-overlapping subarrays which have the largest sum. The number in each subarray should be contiguous. Return the largest sum.
-
Maximum Subarray II
Given an array of integers, find two non-overlapping subarrays which have the largest sum. The number in each subarray should be contiguous. Return the largest sum.
-
44 - Minimum Subarray
Given an array of integers, find the subarray with smallest sum. Return the sum of the subarray.
-
53 - Maximum Subarray
Given an array of integers, find a contiguous subarray which has the largest sum.
-
97 - Interleaving String
Given three strings: s1, s2, s3, determine whether s3 is formed by the interleaving of s1 and s2.
-
Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, "ACE" is a subsequence of "ABCDE" while "AEC" is not).