Pergunta de entrevista da empresa Turo

Series of data structure + algorithm questions centered around finding prime numbers. 1) A function to determine if a given number is prime. 2) A function to return all the primes up to a given number. 3) A function to return the prime factorization of a given number.

Resposta da entrevista

Sigiloso

21 de jul. de 2022

Finding if a number is prime involves determining if any number lower than it divides evenly into it. We can optimize this by checking only primes up to half the number we're interested in, since all other numbers would have also have a been divisible by some prime. So the solution I started writing focused on keeping a running set of prime numbers with a variable to keep track of the range that we've already calculated. I get the impression that the interviewer didn't really understand the reasoning behind my approach. Maybe this could have been cleared up if there was some restriction on the space complexity. But at that point things really went off the rails with me trying to explain what I was doing while the interviewer changed my code to better match his expected solution. In the rejection call the recruiter's only feedback related to this session and something about a redundant if statement. Given that the interviewer took control of the code I was writing so often, which I had to correct errors in more than once, I don't think the feedback was useful.