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.youtube.com/watch?v=XiuSW_mEn7g | |
// maxLen = 3 = numOfIterations | |
// 110, 5, 70... | |
// [ [110,70], [], [], [], [], [5], [], [], [], [] ] | |
// [ [5], [110], [], [], [], [], [], [70], [], [] ] | |
// [ [5,70], [110], [], [], [], [], [], [], [], [] ] | |
// 5, 70, 110 | |
function createSortingArray(base = 10){ | |
return Array.from({length : base}, () => []); | |
} |
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
// autobiographical array | |
// length 10 array | |
// each position has integer representing the count of that index in array | |
function isAutobiographical(arr){ | |
const hash = {}; // key = number in array, value = count of that number | |
for(const num of arr) hash[num] = (hash[num] || 0) + 1; // O(n) | |
for(let i = 0; i < arr.length; i++){ | |
const count = (hash[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
// https://www.hackerrank.com/challenges/contacts/problem | |
class Node{ | |
constructor(char){ | |
this.char = char; | |
this.children = []; // track all following characters | |
this.ends = 0; // keep running total of # of words this char was used in | |
} | |
findOrCreateChild(char){ | |
this.ends++; // increment running count |
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.hackerrank.com/challenges/bomber-man/problem | |
// https://youtu.be/dW15c-PwsXA | |
const EMPTY_CELL = "."; | |
const BOMB_CELL = "O"; | |
function fillGrid(grid){ | |
const col_max = grid[0].length; | |
return grid.fill(BOMB_CELL.repeat(col_max)); | |
} |
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
// source - https://www.hackerrank.com/challenges/new-year-chaos/problem | |
// video - https://youtu.be/vfcALtCXAwQ | |
function minimumBribes(q) { | |
const TOO_CHAOTIC = "Too chaotic"; | |
let total = 0; | |
for(let current_pos = 0; current_pos < q.length; current_pos++){ // O(n) | |
// getting original position using 0 indexing (starts at 0) | |
const original_pos = q[current_pos] - 1; | |
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
# source - https://www.hackerrank.com/challenges/the-grid-search/problem | |
def get_indices_by_char(row, char): | |
return [i for i, letter in enumerate(row) if letter == char] | |
# Complete the gridSearch function below. | |
def gridSearch(grid, pattern): | |
YES = "YES" | |
NO = "NO" | |
grid_rows = len(grid) |
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
# Source - https://www.hackerrank.com/challenges/equal-stacks/problem | |
def allSame(arr): | |
return arr[0]["total"] == arr[1]["total"] == arr[2]["total"] | |
def equalStacks(h1, h2, h3): | |
if(len(h1) == 0 or len(h2) == 0 or len(h3) == 0): | |
return 0; | |
stacks = [ | |
{"arr": h1, "total":sum(h1)}, |
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
// Source - https://www.hackerrank.com/challenges/equal-stacks/problem | |
// Solution by user "manjula dube" - See comment at https://www.youtube.com/watch?v=X9NdolHDm2c&lc=Ugx3ya8xOB2wAj1Oi154AaABAg | |
function equalStacks(h1, h2, h3) { | |
/* | |
* Write your code here. | |
*/ | |
// get the sum of each stack |
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
# source - https://www.hackerrank.com/challenges/the-minion-game/problem | |
def minion_game(string): | |
VOWELS = "aeiou" # y not considered a vowel | |
KEVIN_vowels = 0 | |
STUART_consonants = 0 | |
n = len(string) | |
for i in range(n): # O(n) | |
letter = string[i].lower() # ensuring lowercase comparisons | |
letters_remaining = n - i |
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
# source: https://www.hackerrank.com/challenges/word-order/problem | |
n = int(input()) | |
output = [] | |
for _ in range(n): | |
output.append(input()) | |
def myFunction(strings): | |
# establish hashmap/dictionary |