← Amazon Interview Insights

Amazon·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Amazon data scientist interview with a coding question focused on simulation and pandas. Pretty applied, felt more like a take-home task crammed into a live session. The numpy angle was a nice touch but I fumbled the timestamp logic at first.

Questions Asked (1)

Q1

Write a Python function that generates a simulated clickstream DataFrame with columns for user ID, event timestamp, page visited, and whether the user clicked. Each user should have 1 to 10 random page visits per day over a given number of days, with a 15% click probability.

Algorithms & Data StructuresData Modeling
Author's notes

I started by sketching the loop structure mentally and immediately got tangled on the timestamp part.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the requirements: input parameters (number of users, number of days), output format (pandas DataFrame), and any constraints. Then design a function that loops over users and days, generating a random number of visits per day (1-10) and for each visit a random timestamp, page, and click outcome based on a 15% probability. Finally, assemble the records into a DataFrame and return it.

Pro tip: Use vectorized operations or list comprehensions to generate data efficiently, and set a random seed for reproducibility. Also, consider edge cases like zero users or days and ensure timestamps are realistic (e.g., within the day).

1. Clarify requirements and define inputs

Confirm the function signature: parameters for number of users, number of days, and optionally a random seed. Decide on the date range and how to represent timestamps (e.g., datetime objects).

2. Generate per-user daily visits

For each user and each day, randomly determine the number of visits (1 to 10) using a uniform distribution. This can be done with numpy.random.randint or random.randint.

3. Create event details for each visit

For each visit, generate a random timestamp within the day, a random page from a predefined list (or generate page names), and a click indicator with 15% probability (e.g., using numpy.random.choice or random.random() < 0.15).

4. Assemble and return DataFrame

Collect all records into a list of dictionaries or a list of tuples, then create a pandas DataFrame with the specified columns: user_id, timestamp, page, clicked. Optionally sort by timestamp.

5. Validate and test

Check that the DataFrame has the correct columns, data types, and that the click rate is approximately 15%. Test with small inputs to ensure correctness.

Key Points to Mention

  • Use of random seed for reproducibility
  • Efficient data generation using vectorization or list comprehensions
  • Proper handling of timestamps (e.g., using datetime and timedelta)
  • Click probability implementation (e.g., Bernoulli trial)
  • DataFrame construction with pandas
  • Edge cases: zero users, zero days, and ensuring at least one visit per day per user

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.