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/angry-professo | |
| function angryProfessor(k, a) { | |
| // establishing constants | |
| const YES = "YES"; | |
| const NO = "NO"; | |
| let inClassCount = 0; // keeping running total | |
| for(const arrivalTime of a){ // looping through each arrivalTime; O(n) | |
| inClassCount += arrivalTime <= 0; // get boolean (true/false) if student is late or on time, adding (1/0) to total | |
| if(inClassCount >= k) return NO; // before loop is done, if the total count is past threshold, stop and return NO |
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://leetcode.com/problems/combinations/ | |
| class Solution(object): | |
| def combine(self, n, k): | |
| output = [] | |
| stack = [] | |
| i = 1 | |
| length = 0 | |
| while True: | |
| # if stack if k long, add to solution (as copy) |
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)}, |