Skip to content

Instantly share code, notes, and snippets.

/*
Coin Change - LeetCode: https://leetcode.com/problems/coin-change
All credit for code goes to user @elmirap who wrote the solution
section to this problem: https://leetcode.com/problems/coin-change/solution/
The video to explain this code is here: https://www.youtube.com/watch?v=jgiZlGzXMBw
*/
/*
/*
Climbing Stairs - LeetCode: https://leetcode.com/problems/climbing-stairs
An adaption of the Leetcode "Solution" section with many comments added
for teaching purposes: https://leetcode.com/problems/climbing-stairs/solution/
The video to explain this code is here: https://www.youtube.com/watch?v=NFJ3m9a1oJQ
*/
/*
/*
Coin Change 2 - LeetCode: https://leetcode.com/problems/coin-change-2/
All credit for code goes to user @tankztc:
https://leetcode.com/problems/coin-change-2/discuss/99212/Knapsack-problem-Java-solution-with-thinking-process-O(nm)-Time-and-O(m)-Space
This code passes all Leetcode test cases as of Jan. 11 2019
Runtime: 13ms
Note: This code shows the use of O(mn) space. This problem can be solved using
/*
Maximum Subarray - LeetCode: https://leetcode.com/problems/maximum-subarray/
The video to explain this code is here: https://www.youtube.com/watch?v=2MmGzdiKR9Y
*/
/*
Time Limit Exceeded.
*/
class CubicTimeSolution {
/*
Authorship: All credit for the code in this file goes to the authors of the
book "Elements of Programming Interviews" by Adnan Aziz, Amit Prakash, and
Tsung-Hsien Lee.
I have just added explanatory comments, reformatted the code, & changed
variable names for understanding.
The video to explain this code is here: https://www.youtube.com/watch?v=W9F8fDQj7Ok
*/
/*
Maximum Subarray - LeetCode: https://leetcode.com/problems/maximum-subarray/
The video to explain this code is here: https://www.youtube.com/watch?v=2MmGzdiKR9Y
*/
/*
Time Limit Exceeded.
*/
class CubicTimeSolution {
/*
All Nodes Distance K in Binary Tree - LeetCode: https://leetcode.com/problems/all-nodes-distance-k-in-binary-tree/
This code passes all Leetcode test cases as of Feb. 12th 2019
Runtime: 3 ms, faster than 64.42% of Java online submissions for All Nodes Distance K in Binary Tree.
(can't get much faster than that. Asymptotically this is identical to anything even remotely faster)
The video to explain this code is here: https://www.youtube.com/watch?v=nPtARJ2cYrg
*/
/**
@author Benyam Ephrem
These are the 3 fundamental tree traversals all done recursively.
Very basic, very straightforward. These can be done iteratively
as well as in O(1) space, but then they get trickier to implement
but don't worry. If you can grasp these, you can grasp those.
The video to explain this code is here: https://www.youtube.com/watch?v=BHB0B1jFKQc
/*
Binary Tree Level Order Traversal - LeetCode:
https://leetcode.com/problems/binary-tree-level-order-traversal/
This code passes all Leetcode test cases as of Feb. 3 2019
Runtime: 1 ms, faster than 82.85% of Java online submissions for Binary Tree Level Order Traversal.
Memory Usage: 26.5 MB, less than 64.46% of Java online submissions for Binary Tree Level Order Traversal.
The video to explain this code is here: https://www.youtube.com/watch?v=gcR28Hc2TNQ
*/
/*
Serialize and Deserialize Binary Tree - LeetCode:
https://leetcode.com/problems/serialize-and-deserialize-binary-tree/
This code passes all Leetcode test cases as of April 26 2019
Runtime: 12 ms, faster than 62.25% of Java online submissions for Serialize and Deserialize Binary Tree.
Memory Usage: 39.4 MB, less than 71.37% of Java online submissions for Serialize and Deserialize Binary Tree.
The video to explain this code is here: https://www.youtube.com/watch?v=suj1ro8TIVY
*/