-
-
Save spirinvladimir/dae18d4d5e35edd7ff4cc0671e305d4c to your computer and use it in GitHub Desktop.
Amazon - Online Assessment
This file contains 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
function cellCompete(states, days) { | |
if (days === 0) return states | |
const a = new Array(states.length) | |
states.push(0) | |
states.unshift(0) | |
for (var i = 1; i < states.length - 1; i++) | |
a[i - 1] = states[i - 1] === states[i + 1] | |
? 0 | |
: 1 | |
return cellCompete(a, days - 1) | |
} |
This file contains 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
function generalizedGCD(num, arr) { | |
function gcd (a, b) { | |
var cents = a % b | |
if (cents === 0) return b | |
return gcd(b, cents) | |
} | |
var hcf = arr[0] | |
for (var i = 1; i < num; i++) | |
hcf = gcd(hcf, arr[i]) | |
return hcf | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment