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
// 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/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
// 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://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
// 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://www.youtube.com/redirect?q=https%3A%2F%2Fwww.hackerrank.com%2Fchallenges%2Fwaiter%2Fproblem%3Fh_r%3Dinternal-search&event=video_description&redir_token=QUFFLUhqbWRvZWVfbjJJUVQ0Q2J0WnpTLTVVUnBPYnFYd3xBQ3Jtc0trUXJ5MGF5UVJ5UlgxakpSQnZsXzB0QXY2bk5INzJ4MmhkRk5YLWUzV1RjLXQzX2xqUFl3LUtUVnhlT29QV0VoY3FhOVVqMDZrZ21JQjRXVEdvbUdHR3BZajllbmNuVGJBMTFtcXY0VWxaMGxyUmt1NA%3D%3D&v=UW-1KB9PFrA | |
// video: https://www.youtube.com/watch?v=UW-1KB9PFrA&lc=UgyNhlGoJNiMul7Byad4AaABAg | |
function getPrimes(n){ | |
const primesStr = "2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,7 |
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/kindergarten-adventures | |
# video: https://youtu.be/9vcrruySa9s | |
def sanitize_index(index, n): | |
# index already valid | |
if 0 <= index and index < n: | |
return index | |
# negative index | |
if index < 0: | |
return n + index |
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/gridland-metro | |
# video: https://youtu.be/H1Qbd652Oig | |
def gridlandMetro(n, m, k, tracks): # ALTERED NAME TO PLURAL | |
# tracks = [ | |
# [row, col_start, col_end], | |
# ... | |
# ] | |
# sort by col start | |
tracks.sort(key = lambda track: min(track[1], track[2])) # O(nlogn) |
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/lilys-homework | |
# video: https://youtu.be/HmyDuVZoE8Y | |
def lilysHomework_helper(arr, reverse = False): | |
# clone arr, since modifying | |
arr = arr[:] # O(n)? | |
# arr = [2, 5, 3, 1] | |
# store sorted array | |
sorted_arr = sorted(arr, reverse = reverse) # O(nlogn) | |
# sorted_arr = [1, 2, 3, 5] | |
# OR [5, 3, 2, 1] if reverse = True |