This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Given a 2D board and a word, find if the word exists in the grid. | |
| * The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically neighboring. | |
| * The same letter cell may not be used more than once. | |
| * For example, | |
| * Given board = | |
| * [ | |
| ["ABCE"], | |
| ["SFCS"], | |
| ["ADEE"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram. | |
| * Above is a histogram where width of each bar is 1, given height = [2,1,5,6,2,3]. | |
| * The largest rectangle is shown in the shaded area, which has area = 10 unit. | |
| * For example, | |
| * Given height = [2,1,5,6,2,3], | |
| * return 10. | |
| */ | |
| public class Solution { | |
| public int largestRectangleArea(int[] height) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area. | |
| */ | |
| public class Solution { | |
| public int maximalRectangle(char[][] matrix) { | |
| int m = matrix.length; | |
| int n = m == 0 ? 0 : matrix[0].length; | |
| int[][] height = new int[m][n]; | |
| int maxArea = 0; | |
| for(int i = 0; i < m; i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that: | |
| * 1. Only one letter can be changed at a time | |
| * 2. Each intermediate word must exist in the dictionary | |
| * For example, | |
| * Given: | |
| * start = "hit" | |
| * end = "cog" | |
| * dict = ["hot","dot","dog","lot","log"] | |
| * As one shortest transformation is "hit" -> "hot" -> "dot" -> "dog" -> "cog", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. | |
| * Below is one possible representation of s1 = "great": | |
| * great | |
| / \ | |
| gr eat | |
| / \ / \ | |
| g r e at | |
| / \ | |
| a t |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Validate if a given string is numeric. | |
| * Some examples: | |
| * "0" => true | |
| * " 0.1 " => true | |
| * "abc" => false | |
| * "1 a" => false | |
| * "2e10" => true | |
| * Note: It is intended for the problem statement to be ambiguous. You should gather all requirements up front before implementing one. | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * A message containing letters from A-Z is being encoded to numbers using the following mapping: | |
| * 'A' -> 1 | |
| * 'B' -> 2 | |
| * ... | |
| * 'Z' -> 26 | |
| * Given an encoded message containing digits, determine the total number of ways to decode it. | |
| * For example, | |
| * Given encoded message "12", it could be decoded as "AB" (1 2) or "L" (12). | |
| * The number of ways decoding "12" is 2. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Given a string containing only digits, restore it by returning all possible valid IP address combinations. | |
| * For example: | |
| * Given "25525511135", | |
| * return ["255.255.11.135", "255.255.111.35"]. (Order does not matter) | |
| */ | |
| public class Solution { | |
| public ArrayList<String> restoreIpAddresses(String s) { | |
| ArrayList<String> res = new ArrayList<String>(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. | |
| * For example, | |
| * Given: | |
| * s1 = "aabcc", | |
| * s2 = "dbbca", | |
| * When s3 = "aadbbcbcac", return true. | |
| * When s3 = "aadbbbaccc", return false. | |
| */ | |
| public class Solution { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Given a binary tree, find the maximum path sum. | |
| * The path may start and end at any node in the tree. | |
| * For example: | |
| * For example: | |
| * 1 | |
| / \ | |
| 2 3 | |
| * Return 6. | |
| */ |