0 day streak
Anonymous · shared experience20 Jun 2025 · 10 views

Snap: Implement sine from scratch with a series expansion and a stopping rule

Interview question #Snap Staff+ Phone screen

Problem. Write your own version of a library sine function: take a number x (in radians) and return sin(x) as a double, without calling the built-in. The suggested route is the Taylor series for sine.

The two hard parts the candidate called out

  1. Termination: the series is infinite, so you need a clear rule for when to stop adding terms instead of looping forever.
  2. Precision: decide what accuracy the result should target and how that ties into the stopping rule.

Context. This was the phone screen for a staff-level role in the US. The candidate passed to the onsite but needed a few hints and was downleveled.

What to prepare. Computing each term from the previous one instead of recomputing factorials and powers, stopping once a term falls below a tolerance, and reducing large inputs into a small range first so the series converges fast and stays accurate. No examples or extra constraints were given in the post.

0 comments

Comments 0

No comments yet. Ask the author something, or add what happened in your own round.