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/organizing-containers-of-balls | |
function organizingContainers(containers) { | |
const n = containers.length; | |
// keep # of balls per container | |
const containerCounts = new Array(n).fill(0); | |
// keep # of types of balls | |
const ballTypes = new Array(n).fill(0); | |
for(let i = 0; i < 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/down-to-zero-ii | |
#!/bin/python3 | |
import os | |
import sys | |
MAX_N = 10 ** 6 | |
# list of values by index, index corresponds to # of steps |
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
// Original TED Riddle Video: https://www.youtube.com/watch?v=YeMVoJKn1Tg | |
// check if number valid | |
function state_is_valid(array, two_found, ten_found){ | |
// whole number | |
// not great than 60 | |
// no duplicates | |
const last_num = array[array.length-1]; | |
const normal_check = Math.floor(last_num) == last_num && last_num <= 60 && !has_duplicates(array); | |
if(normal_check){ |
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/piling-up/problem | |
def myFunction(sideLengths): | |
curr_cube_length = float("inf") | |
left_runner = 0 | |
right_runner = len(sideLengths) - 1 | |
while left_runner <= right_runner: # O(n) | |
left_val = sideLengths[left_runner] | |
right_val = sideLengths[right_runner] |
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 |
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/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/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/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/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; | |