Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Prime and Fibonacci Coding

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Prime and Fibonacci Coding. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

UST QA automation utilities need deterministic numeric datasets for validating boundary conditions and performance. Implement a function that returns every prime number up to an inclusive limit and the first count Fibonacci numbers modulo 1_000_000_007.

Use an efficient odd-only Sieve of Eratosthenes for prime generation. The Fibonacci sequence begins with 0, 1, so the first count values are F(0) through F(count - 1).

Formal Specification

Implement generate_sequences(limit, count).

  • Input: limit, an integer defining the inclusive upper bound for prime search, and count, an integer defining the number of Fibonacci values.
  • Output: A dictionary with two keys:
    • primes: a list of all primes in ascending order from 2 through limit.
    • fibonacci: a list of count integers, where each value is F(i) % 1_000_000_007.

Constraints

  • 1 <= limit <= 10^7
  • 0 <= count <= 10^6
  • Fibonacci values are returned modulo 1,000,000,007
  • Prime values are returned in ascending order

Function Signature

def generate_sequences(limit, count):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output