You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return 1.
[Read More…]

LeetCode Coin Change

LeetCode Shortest Word Distance III
This is a follow up of Shortest Word Distance. The only difference is now word1 could be the same as word2.
Given a list of words and two words word1 and word2, return the shortest distance between these two words in the list.
word1 and word2 may be the same and they represent two individual words in the list.
[Read More…] 
LeetCode Shortest Word Distance II
This is a follow up of Shortest Word Distance. The only difference is now you are given the list of words and your method will be called repeatedly many times with different parameters. How would you optimize it?
Design a class which receives a list of words in the constructor, and implements a method that takes two words word1 and word2 and return the shortest distance between these two words in the list.
[Read More…] 
LeetCode Shortest Word Distance
Given a list of words and two words word1 and word2, return the shortest distance between these two words in the list.
[Read More…] 
LeetCode Verify Preorder Sequence in Binary Search Tree
Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary search tree.
You may assume each number in the sequence is unique.
[Read More…] 
LeetCode Binary Tree Upside Down
Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node that shares the same parent node) or empty, flip it upside down and turn it into a tree where the original right nodes turned into left leaf nodes. Return the new root.
[Read More…] 
LeetCode Count Univalue Subtrees
Given a binary tree, count the number of univalue subtrees.
A Univalue subtree means all nodes of the subtree have the same value.
[Read More…] 
LeetCode Inorder Successor in BST
Given a binary search tree and a node in it, find the inorder successor of that node in the BST.
Note: If the given node has no inorder successor in the tree, return null.
[Read More…]