Sign in to save your progress, vote, and build your own decks.Sign in
Prep Kit - Arrays
16 cards·by luc-yahoo
hackerrank
2D sum sections: summary
use nested for loops
2D sum sections: find max of a section
init the max to a known min and increment as new maxes are found
2D sum sections: how many times to loop?
how many sections fit in the array?
left rotation: number of rotations is equiv to
break position
left rotation: how many rotations aka
number to cut from the left
min bribes: how to detect when to exit fast
if the position is too distant from the value
flip and invert a binary array
use two pointers, 1 at each end. invert if the values are the same
Min swaps: define swap func, taking:
whole array, two positions to swap
Min swaps: swap function
set temp to pos1, copy pos2 to pos1, copy temp to pos2
Min swaps: when to call the swap function?
??
Minimum difference: set res to:
math.inf
Minimum difference: which position to start at?
start at position 1, so we compare each number to the previous
Minimum difference: how to check difference?
diff = min(arr[i+1] - arr[i], res)
Jumping on Clouds: what kind of loop
while loop
Jumping on the Clouds; how to check if close to the end
if pos + 2 > end: increment pos by 1 and jumps by 1
Jumping on the Clouds; how many cases
3; close to the end, a valid long jump, a short jump