Skip to content

Instantly share code, notes, and snippets.

View Shaddyjr's full-sized avatar
📉
You must construct additional models

Mahdi Shadkam-Farrokhi Shaddyjr

📉
You must construct additional models
View GitHub Profile
// 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
# 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)
// 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++){
# 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
// 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){
# 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]
# 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
# 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
// 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
# 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)},