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; | |
/** | |
Given a sum, and a list of non-unique integer, find a combo that sums up to that target, or the closest. | |
Eg [2, 3, 3, 4], target = 5 | |
O/p = [2, 3] | |
[2, 3, 3, 4], target = 8 | |
O/p = [2, 3, 3] | |
[2, 3, 3, 4], target = 15 | |
O/p = [2, 3, 3, 4] |
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
// ... topological sort content | |
hasCycle() { | |
inRecursionStack = []; | |
marked = []; | |
for (int i = 0; i < vertices; i++) { | |
if (cycleDFS(i, inRecursionStack)) return true; | |
} | |
return false; | |
} |
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 Digraph from './Digraph' | |
class topologicalSort { | |
constructor(graph) { | |
this.g = graph; | |
this.vertices = g.V(); | |
this.marked = []; // contains the visited vertices | |
this.postOrder = []; | |
} |
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
export class Digraph { // exported so we can use it in topological sort | |
constructor(v) { | |
this.v = v; // initialize the number of vertices | |
this.e = 0; // and edges | |
this.adj = {}; // this object contains thevertices connected to each vertex. | |
} | |
addEdge(v, w) { | |
if (!adj[v]) adj[v] = []; // check if the vertex already exist, if not, created it | |
adj[v].push(w); // push the connecting edge vertex to its array of vertices |
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
/* eslint-disable no-console */ | |
require('dotenv').config(); | |
const cluster = require('cluster'); | |
const jwt = require('jsonwebtoken'); | |
const backgroundJobHandler = require('background_job_handler'); | |
const app = require('./appREST'); | |
const rpc = require('./appRPC'); | |
const { DB } = require('./api/models'); |
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
hello(5) | |
hello(4) | |
hello(3) | |
hello(2) | |
hello(1) | |
hello(0) | |
hello(-1) | |
--- | |
console.log(-1) // and other statements left | |
console.log(0) // and other statements left |
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
function hello(i) { | |
if (i < 0) return; // base case | |
console.log(i); | |
hello(--i); // recursive call | |
} | |
hello(5); // output: 5 4 3 2 1 0 | |
function hello(i) { |
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
function fact(n) { | |
if (n == 1) return n; // base case | |
return n * fact(n - 1); // recursive call | |
} | |
// fact(5) analysis - output = 120 | |
fact(5) | |
5 * fact(4) | |
5 * (4 * fact(3)) |
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
let i = 5; // I've chosen an arbitrary number | |
while (i > 0) { | |
console.log(i--); | |
} | |
// output: 5 4 3 2 1 |
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
function hello(i) { | |
if (i < 0) return; // base case | |
console.log(i); | |
hello(--i); // recursive call | |
} | |
hello(5) // output: 5 4 3 2 1 0 |
NewerOlder