This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
public class CountNegativeIntegersInMatrix { | |
public static void main(String[] args) { | |
int[][] data = new int[][]{ | |
{-3, -2, -1, 0, 1, 2, 4, 6, 7, 8}, | |
{-3, -2, -1, 1}, | |
{-2, 2, 3, 4}, | |
{4, 5, 7, 8} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Scanner; | |
public class TrafficLight { | |
public static void main(String[] args) throws InterruptedException { | |
Road north = new Road(Direction.NORTH, Color.RED); | |
Road south = new Road(Direction.SOUTH, Color.RED); | |
Road east = new Road(Direction.EAST, Color.RED); | |
Road west = new Road(Direction.WEST, Color.RED); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
* Paths with Sum: You are given a binary tree in which each node contains | |
* an integer value (which might be positive or negative). | |
* Design an algorithm to count the number of paths that sum to a given value. | |
* The path does not need to start or end at the root or a leaf, | |
* but it must go downwards (traveling only from parent nodes to child nodes). | |
* <p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
* Check Subtree: T1 and T2 are two very large binary trees, with T1 much bigger than T2. | |
* Create an algorithm to determine if T2 is a subtree of T1. | |
* A tree T2 is a subtree of T1 if there exists a node n in T1 such that the subtree of n is identical to T2. | |
* That is, if you cut off the tree at node n, the two trees would be identical. | |
* <p> | |
* Hints: #4, #77, #78, #37, #37 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Successor: Write an algorithm to find the "next" node (i.e., in-order successor) | |
* of a given node in a binary search tree. You may assume that each node has a link to its parent. | |
* Hints: #79, #91 | |
*/ | |
public class Successor { | |
public static void main(String[] args) { | |
Node n6 = new Node(25, null, null, null); | |
Node n5 = new Node(13, null, null, null); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Validate BST: Implement a function to check if a binary tree is a binary search tree. | |
* Hints: #35, #57, #86, # 773, # 728 | |
*/ | |
public class ValidateBST { | |
public static void main(String[] args) { | |
Node n6 = new Node(25, null, null); | |
Node n5 = new Node(13, null, null); | |
Node n4 = new Node(8, null, null); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
/** | |
* Build Order: You are given a list of projects and a list of dependencies | |
* (which is a list of pairs of projects, where the second project is dependent on the first project). | |
* All of a project'sdependencies must be built before the project is. | |
* Find a build order that will allow the projects to be built. | |
* If there is no valid build order, return an error. | |
* <p> | |
* EXAMPLE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Check Balanced: Implement a function to check if a binary tree is balanced. | |
* For the purposes of this question, a balanced tree is defined to be a tree such that | |
* the heights of the two subtrees of any node never differ by more than one. | |
* <p> | |
* Hints : # 27, # 33 , # 49 , # 705 , # 724 | |
*/ | |
public class CheckBalanced { | |
public static void main(String[] args) { | |
Node n10 = new Node(14, null, null); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.LinkedList; | |
/** | |
* List of Depths: Given a binary tree, design an algorithm which creates | |
* a linked list of all the nodes at each depth (e.g., if you have a tree with depth 0, you'll have 0 linked lists). | |
* Hints: #107, #123, #735 | |
*/ | |
public class ListOfDepths { | |
public static void main(String[] args) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.LinkedList; | |
/** | |
* Route Between Nodes: Given a directed graph, design an algorithm to find out | |
* whether there is a route between two nodes. | |
* Hints: #127 | |
*/ | |
public class RouteBetweenNodes { | |
public static void main(String[] args) { | |
// Node node8 = new Node("node8", new Node[]{}); |
NewerOlder