Recent Posts all posts
Goals¶
- Understand various graph representations
- Recognize problems that can be solved with graphs
- Know how to quickly implement graph searches (BFS, DFS)
- Recognize topological sort graph problems
Keep in mind that during interviews coding questions are usually allotted 30-40 minutes. Given that time constraint, you should aim to spend around …
Here I solve the Path Sum - LeetCode problem from LeetCode:
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.
Note: A leaf is a node with no children.
Example:
Given …
Here we solve the Happy Number Problem from LeetCode.
Write an algorithm to determine if a number
n
is “happy”.A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat …
This post solves the Implement Queue using Stacks - LeetCode problem.
Implement the following operations of a queue using stacks.
- push(x) — Push element x to the back of queue.
- pop() — Removes the element from in front of queue.
- peek() — Get the front element.
- empty() — Return whether the queue is empty …
Here we solve the Valid Sudoku Problem from LeetCode.
Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:
- Each row must contain the digits
1-9
without repetition.- Each column must contain the digits
1-9
without repetition.- Each of …
Here we solve the Find K Pairs with Smallest Sums problem from LeetCode:
You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k.
Define a pair (u,v) which consists of one element from the first array and one element from the second …
Here we solve the Sum of Left Leaves - LeetCode problem from LeetCode:
Find the sum of all left leaves in a given binary tree.
Example:
“` 3 / \ 9 20 / \ 15 7
There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24. “`
This is an …
Here we solve the Top K Frequent Words from LeetCode.
Given a non-empty list of words, return the k most frequent elements.
Your answer should be sorted by frequency from highest to lowest. If two words have the same frequency, then the word with the lower alphabetical order comes first …
Goals¶
- Know how to search for values in binary search tree in optimal way
- Understand and be able to implement the following types of traversals, including when to use them and their tradeoffs
- In-order, pre-order, post-order
- BFS
- DFS
- Understand how to implement at least one traversal in iterative approach
- Understand …
This post is an in-depth explanation of the Largest Rectangle in Histogram problem from LeetCode based on this solution by user dietpepsi:
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 …