This file contains hidden or 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 G = [ | |
| [0, 2, 5, Infinity], | |
| [2, 0, Infinity, 7 ], | |
| [5, Infinity, 0, Infinity], | |
| [Infinity, 7, Infinity, 0 ]]; | |
| let N = G.length; | |
| let target = 3; // target is to visit 3rd | |
| let distance = new Array(N).fill(Infinity); | |
| let visited = new Array(N).fill(false); |
This file contains hidden or 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
| class QElement { | |
| constructor (value, priority) { | |
| this.value = value; | |
| this.priority = priority | |
| } | |
| } | |
| class PQ { | |
| constructor () { | |
| this.elements = ['root']; |
This file contains hidden or 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 finalResult = []; | |
| function printBinary(number) { | |
| let chosen = []; | |
| printBinaryHelper(number, chosen); | |
| } | |
| function printBinaryHelper(count, chosen) { | |
| if (count == 0) { | |
| // base case |
This file contains hidden or 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 names = ["fifi", "vampire", "lena", "wheels"]; | |
| let finalResult = []; | |
| function sublist(array) { | |
| let chosen = []; | |
| sublistHelper(array, chosen); | |
| } | |
| function sublistHelper(array, chosen) { | |
| if (array.length == 0) { |
This file contains hidden or 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 travel(temp, level) { | |
| if (count.every(element => element == 0) ) { | |
| result.push(temp.join('')); | |
| return; | |
| } | |
| for (let i = 0; i < count.length; i++) { | |
| if (count[i] > 0) { |
This file contains hidden or 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 indexOf(string, query) { | |
| for (let i = 0; i < string.length; i++) { | |
| //str.charAt(i) | |
| for (let q = 0; q < query.length; q++) { | |
| if (string[i+q] != query[q]) { | |
| break; | |
| } |
This file contains hidden or 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 basicCalc(str) { | |
| let result = 0, length = str.length, sign = 1, char; | |
| let stack = []; | |
| for (let i = 0; i < length; i++) { | |
| char = str.charAt(i); | |
| if (char >= '0') { | |
| //find all the chars | |
| let num = 0; |
This file contains hidden or 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
| // https://www.geeksforgeeks.org/delete-consecutive-words-sequence/ | |
| function deleteConsecutive(arr) { | |
| let stack = new Stack(); | |
| arr.forEach(element => { | |
| if (element == stack.peek()) { | |
| stack.pop(); | |
| } else { | |
| stack.push(element); | |
| } |
This file contains hidden or 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
| const arr = [-1, -1, 1, 1, 1, 1, 7, 11, 11]; | |
| // [ -1, 2, 1, 4, 7, 1, 11, 2]; | |
| class Stack { | |
| constructor() { | |
| this.values = []; | |
| } | |
| push(v) { |
This file contains hidden or 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
| const arr = [0, -1, 2, -3, 1]; | |
| // [ -3, -1, 0, 1, 2 ] | |
| function triplets(arr) { | |
| let sorted = arr.sort((a, b) => { return a > b; }); | |
| let answer = []; | |
| for(p1 = 0; p1 < sorted.length - 2; p1++) { |
NewerOlder