Twitch Interview Question

Create a function to find if a number is prime.

Interview Answers

Anonymous

Mar 8, 2017

if there are no other assumptions, you can check for divisible numbers until sqrt(n) func isPrime(n: Int) -> Bool { if n n { return true } if n % i == 0 { return false } } return true } if this function is going to be called multiple times, then you can spend some time pre-computing a list of primes func calculatePrimes(to n: Int) { var pensieve = Array(repeating: 0, count: n) var i = 2 while i < n { if (pensieve[i] == 0) { primeList.append(i) } var j = i while j < n { pensieve[j] = 1 j += i } i += 1 } }

Anonymous

Jan 26, 2021

Through questions like this, interviewers are mostly trying to test your skillset (and its relevance to the role) as robustly as possible, so be prepared for multiple offshoots and followups. It could be a useful exercise to do mocks with friends or colleagues in Twitch to get a real sense of what the interview is actually like. Alternatively Prepfully has a ton of Twitch Web Developer experts who provide mock interviews for a pretty reasonable amount. prepfully.com/practice-interviews