Assume we're using a binary tree in writing a video game via Binary Space Partitioning. We need to identify the bottom left leaf, that is-- the leftmost value in the lowest row of the binary tree.
<img src="https://...
We are given a binary tree and are tasked with writing a method that determines the average of every level in the tree. So for instance, given the following binary tree, we'd get [2, 5, 7] if the method grabbed the correct means.
<img src="https://storage.googleapis.com/a...
Given a binary tree, write a method to return an array containing the largest (by value) node values at each level. In other words, we're looking for the max per level.
So for instance, given the following binar...
Here's a fun one: can you write a method to return the nodes of a binary tree in a zig zag level order?
It should return a multi-dimensional array of...
Building a Queue with Two Stacks: A Challenge in Engineering Elegance
The Queue with Stacks
In this challenge, your task is to implement a queue using two stacks. While many programming languages offer queues through arrays or lists, we're restricting our approach to only utilize stacks.
The end result should b...
Imagine two words placed at the two ends of a ladder. Can you reach one word from another using intermediate words as rings of the ladder? Each successive or transition word has a difference of only one letter from its predecessor, and must belong to a provided dictionary. Can we achieve this using the shortest possible number of r...
Question
Given a graph, can you use two colors to color each node of the graph, such that no two adjacent nodes have the same color?
The Problem
The graph coloring problem is a well-known problem in computer science. It requires coloring different node...
Cheat Sheet
Quick summary: a sequential collection where elements are added at one end and removed from the other end.
Important facts:
Modeled after a real-life queue: first come, first served.
First in, first out (FIFO) data structure.
Similar to a linked list, the first (last added) node is called the tail, and the last (next to be removed) node is called the head.
Two fundamental operations are enqueuing and dequeuing:
To enqueue, insert at the tail of the linked list.
To dequeue, remove at the head of the linked list.
Usually implemented on top of linked lists because they're optimized for insertion and deletion, which are used to enqueue and dequeue elements.
Pros:
Constant-time insertion and deletion.
Cons:
Access and search are O(n).
Notable uses:
CPU and disk scheduling, interrupt handling and buffering.