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
public class App { | |
public static void main(String[] args) { | |
Vertex v1 = new Vertex("A"); | |
Vertex v2 = new Vertex("B"); | |
Vertex v3 = new Vertex("C"); | |
v1.addNeighbour(new Edge(1, v1, v2)); | |
v1.addNeighbour(new Edge(10, v1, v2)); | |
v2.addNeighbour(new Edge(1, v2, v3)); |
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.List; | |
import java.util.stream.Stream; | |
import static java.util.stream.Collectors.toList; | |
class Armstrong { | |
/** | |
* /** | |
* Java 8 / Lambda approach to generate Armstrong number. |
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.List; | |
import java.util.stream.Stream; | |
import static java.util.stream.Collectors.toList; | |
public class Fibonacci { | |
/** | |
* Java 8 / Lambda approach to generate fibonacci series. | |
* Fibonacci always start as classic (e.g. 0, 1, 1, 2, 3, 5) | |
* @param series Number of how many fibonacci number should be generated |
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); |
NewerOlder