PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates a candidate's ability to implement synthetic data generation and probabilistic event simulation in Python using libraries like pandas and numpy, emphasizing timestamp handling, random sampling, and feature engineering for clickstream records.

  • medium
  • Amazon
  • Coding & Algorithms
  • Data Scientist

Generate Synthetic Clickstream Data with Python Function

Company: Amazon

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

##### Scenario The analytics team needs to generate synthetic click-stream records to test a new reporting pipeline before real traffic arrives. ##### Question Write a Python function simulate_clickstream(num_users: int, days: int) that returns a Pandas DataFrame of simulated events with columns [user_id, event_ts, page, clicked]. Events should be timestamped within the past <days> days, each user should visit 1–10 random pages per day, and click probability is 0.15. ##### Hints Use numpy.random for page counts and probabilities; build a list of dicts, then convert to DataFrame.

Quick Answer: This question evaluates a candidate's ability to implement synthetic data generation and probabilistic event simulation in Python using libraries like pandas and numpy, emphasizing timestamp handling, random sampling, and feature engineering for clickstream records.

Implement simulate_clickstream(num_users, days, seed=0) to generate a reproducible list of synthetic click-stream events. Return a list of dicts with keys [user_id, event_ts, page, clicked]. Use these rules: (1) Use BASE=1700000000 (Unix seconds) as a fixed 'now'. For each day d in [0..days-1], day_start = BASE - (d+1)*86400. (2) Pages = ["home", "search", "product", "cart", "checkout"]. (3) For each user u in [1..num_users] and each day d, generate k = 1 + ((seed + 31*u + 17*d) % 10) events. For each event j in [0..k-1]: page_idx = (seed + 37*u + 11*d + 13*j) % 5; offset = (seed + 97*u + 101*d + 103*j) % 86400; clicked = 1 if ((seed + 131*u + 137*d + 139*j) % 100) < 15 else 0; event_ts = day_start + offset. (4) Sort the final list by (event_ts asc, user_id asc, page asc). Return [] if num_users <= 0 or days <= 0.

Constraints

  • 0 <= num_users <= 1000
  • 0 <= days <= 30
  • Each user generates 1..10 events per day
  • event_ts is in [BASE - days*86400, BASE)
  • Return events sorted by (event_ts, user_id, page)

Hints

  1. Iterate days then users; compute k events per user per day using the provided modular formulas.
  2. Append dicts to a list and sort by (event_ts, user_id, page) before returning.
  3. Return an empty list when num_users <= 0 or days <= 0.
Last updated: Mar 29, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Minimum Path Length Through a Grid With One Allowed Cell Conversion - Amazon (medium)
  • Circular Drone Hub Delivery Route - Amazon (hard)
  • Leaf Domain Cumulative Scores - Amazon (medium)
  • Kth Largest Perfect Binary Subtree - Amazon (medium)
  • Find Conflicting Events - Amazon (medium)