Skip to content

Instantly share code, notes, and snippets.

@spirinvladimir
Last active November 6, 2019 09:26
Show Gist options
  • Save spirinvladimir/dae18d4d5e35edd7ff4cc0671e305d4c to your computer and use it in GitHub Desktop.
Save spirinvladimir/dae18d4d5e35edd7ff4cc0671e305d4c to your computer and use it in GitHub Desktop.
Amazon - Online Assessment
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)
}
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