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
#include <iostream> | |
#include <queue> | |
// A node class representing nodes in a Binary Search Tree | |
class Node { | |
public: | |
int data; | |
Node *left; | |
Node *right; | |
// default constructor |
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
var [r, g, b] = new Array(3).fill(0).map((_, i) => Math.floor(Math.random() * 256); | |
console.log(r, g, b); | |
// 11 210 159 |
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
// Iterative Approach - traverse the tree level by level performing bfs | |
// O(n) time and O(n) space where n = number of nodes in the BST | |
vector<vector<int>> levelOrder(TreeNode* root) { | |
if (root == NULL) return {}; | |
// list to store each level of nodes | |
vector<vector<int>> levels; | |
// queue holding node pointers which we process during the traversal | |
queue<TreeNode*> q; | |
// add "enqueue" the root node as that will be the first node we process | |
q.push(root); |
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
// O(n) time and O(n) space where n = length of the input sequence | |
template <typename T> | |
bool containsDuplicate(std::vector<T> &sequence) { | |
std::unordered_set<T> uset; | |
for (auto val : sequence) { | |
if (uset.count(val) > 0) { | |
return true; | |
} | |
uset.insert(val); | |
} |
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
// Iterative: O(log(n)) time and O(1) space | |
// Recursive: O(log(n)) time and O(log(n)) space | |
template <typename T> | |
int binarySearchIterative(std::vector<T> arr, T target) { | |
int left = 0, right = arr.size()-1; | |
while (left <= right) { | |
int mid = left + ((right-left) / 2); | |
if (target == arr[mid]) { | |
return mid; |
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
package app; | |
import java.util.Map; | |
import java.util.HashMap; | |
import java.util.Map.Entry; | |
import java.util.List; | |
import java.util.ArrayList; | |
import java.util.Collections; | |
public class ChessMapping { | |
public Map<String, int[]> chessCodeToCartesian; |
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
class Alphabet { | |
constructor() { | |
this.lowercaseStr = ''; | |
this.uppercaseStr = ''; | |
this.lowercaseArr = []; | |
this.uppercaseArr = []; | |
this.letters = this.getAlphabet(); | |
this._init(); | |
} |
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 getAlphabet(lowercase) { | |
const alphabet = []; | |
const start = lowercase ? 65 : 97; | |
const end = lowercase ? 91 : 123; | |
for (let i=start, j=0; i < end; i++, j++) { | |
alphabet[j] = String.fromCharCode(i); | |
} | |
return alphabet; | |
} |
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
async function writeCiphers(cipherObj) { | |
if (!cipherObj) return | |
const allCiphers = [] | |
const {input, folder, filename, customRotations, useAscii, randomRotations} = cipherObj; | |
let uniform = makeSectionHeader(input, 'Uniform Rotations') | |
let custom = makeSectionHeader(input, 'Custom Rotations', true) | |
let unique = makeSectionHeader(input, 'Random Rotations', true) | |
const uniformCiphers = getUniformCiphers(input, useAscii) | |
uniform += uniformCiphers.join('\n') |