Marcy Blog

Failed to be a geek

Problem: Pacific Atlantic Water Flow

Question Given an m x n matrix of non-negative integers representing the height of each unit cell in a continent, the “Pacific ocean” touches the left and top edges of the matrix and the “Atlantic...

Problem: The Maze

Question There is a ball in a maze with empty spaces and walls. The ball can go through empty spaces by rolling up, down, left or right, but it won’t stop rolling until hitting a wall. When the ba...

Problem: Longest Increasing Path in a Matrix

Question Given an integer matrix, find the length of the longest increasing path. From each cell, you can either move to four directions: left, right, up or down. You may NOT move diagonally or m...

Problem: Decode String

Question Given an encoded string, return it’s decoded string. The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note ...

Problem: Subsets II

Question Given a set of distinct integers, nums, return all possible subsets (the power set). Note: The solution set must not contain duplicate subsets. For example, If nums = [1,2,3], a solutio...

Problem: Palindrome Permutation II

Question Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empty list if no palindromic permutation could be form. For example: Given s = "aabb", re...

Problem: Permutations II

Question Given a collection of distinct numbers, return all possible permutations. For example, [1,2,3] have the following permutations: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], ...

Problem: Combination Sum

Question Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target. Th...

Problem: Combination Sum III

Question Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers. Note: A...

Problem: Combination Sum II

Question Given a set of candidate numbers (candidates) (with duplicates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target. The s...