Posts

Showing posts from April, 2019

HackerRank: Migratory Birds (Easy)

Link to code challenge Naive approach. function migratoryBirds(arr) { let num = Infinity; let count = 0; let largestCount = 0; let newArr = arr.sort(); for (let i = 0; i largestCount) { largestCount = count; num = newArr[i - 1]; } //DON'T need this else if statement since newArr[i - 1] will always be greater than num as the arr is in numerical order else if (count === largestCount) { if (newArr[i - 1]

HackerRank: Birthday Chocolate (easy)

Link to code challenge function birthday(s, d, m) { let count = 0; let pointer = 0; while (pointer

HackerRank- Kangaroo (easy)

Link to code challenge Needed assistance on 2nd formula instead of doing an iteration. You first find the difference between the starting points of the two kangaroos. Next, you find the difference between the speed at which each kangaroo travels. This difference is how much the distance between the two kangaroos is decreasing by at each "iteration". Therefore, the difference in speed has to be a factor of the difference in their starting points in order for both kangaroos to eventually be on the same points. If the difference in distance is 7 but at each iteration the distance is reduced by 2, they will never be on the same point (7 / 2 !== 0). function kangaroo(x1, v1, x2, v2) { let pos1 = x1; let pos2 = x2; if ( (x1 > x2 && v1 > v2) || (x1