Arrays Spiral Matrix Leetcode Problem Statement Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. Example 1: Input: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] Output: [1,2,3,6,9,8,7,4,
Leetcode Medium Longest Palindromic Substring Java Problem Statement Given a string, Find the longest palindromic substring. Solution Explanation Understanding the question here is very simple, given a string RENTNOW, the substring NTN is a palindrome of length 3, and that would be the result. Brute Force Before we think of
Array Find K Pairs with Smallest Sum Java Solution Problem Statement Given two integer arrays, arr1 and arr2, find K pairs of elements such that (x,y) where x is the value from the first array and y is the value from the second array who sum is the smallest. For example, give
Array Check If a Sudoku is Valid Problem Statement Determine if a sudoku is Valid. Solution Explanation Given a sudoku grid, we need to verify if the already filled in numbers doesn't violate the sudoku rules. The rules are very simple, Each row has numbers from 1-9 and no repitions Each
Math Generate all Factor Combinations Problem Statement Given a number 'n', generate all factor combinations. For example, when n=24, the result would be [[2, 3, 3], [2, 9], [3, 6]] Solution Explanation As we know, every integer can be formed by product or multiplication of some numbers. These
Leetcode Medium Find Inorder Successor in a Binary Search Tree Problem Statement Given a binary search tree and the value of a certain node, find the next node in the inorder sequence after the given node. Solution Explanation The important information here is that the tree is a binary search tree and we need
Array Number of Islands Leetcode Problem Statement Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are
Math Find the Celebrity Problem Statement Suppose you are at a party with n people (labeled from 0 to n - 1) and among them, there may exist one celebrity. The definition of a celebrity is that all the other n - 1 people know him/her but
Array Three Sum(3Sum) Leetcode Problem Statement Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Solution Explanation Given an integer array like below,
Array Meeting Rooms Leetcode Problem Statement Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), find the minimum number of conference rooms required. For example, Given [[0, 30],[5, 10],[15, 20]], return 2. Solution Explanation The
String Decode Ways Leetcode Problem Statement 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.
String Letter Combinations of a Phone Number Problem Statement Given a digit string, return all possible letter combinations that the number could represent. Input:Digit string "23" Output: ["ad", "ae", "af", "bd", "be", "bf", "cd"
Binary Tree Binary Tree Vertical Order Traversal Leetcode Problem Statement Given a binary tree, return the vertical order traversal of its nodes' values. (ie, from top to bottom, column by column). Solution Explanation Given a binary tree, 35 / \ 23 27 / \ \ 14 10 9 vertical order traversal looks like this, [[14], [23], [35,
Array Sparse Matrix Multiplication Problem Statement Given two sparse matrices A and B, return the result of AB. You may assume that A's column number is equal to B's row number. Solution Explanation A sparse matrix is a matrix or a 2D array in which majority of the