PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Hudson

Count players reaching end with moving watchers

Last updated: Mar 29, 2026

Quick Overview

This question evaluates skills in discrete-event simulation, stateful time-step modeling, and range coverage by moving agents, as well as algorithmic efficiency for processing flip events and large input sizes.

  • easy
  • Hudson
  • Coding & Algorithms
  • Software Engineer

Count players reaching end with moving watchers

Company: Hudson

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

You are given a 1D line of **L** cells indexed **0..L-1**. The **end cell** is **L-1**. There are: - **W watchers** with initial integer positions `watchers[]`. - **P players** with initial integer positions `players[]`. - A time horizon **T** (non-negative integer, number of unit-time steps). - An unsorted list `flipTimes[]` of integer timestamps. **At each timestamp `t` in `flipTimes`, all watchers reverse direction**. Movement model (discrete time): - Time steps are `t = 0, 1, ..., T-1`. - Each watcher has a facing direction (`LEFT` or `RIGHT`). **All watchers start facing LEFT at time 0**. - At the **start** of each step `t`, if `t` is in `flipTimes`, all watchers reverse direction. - **Watching rule:** At step `t`, a watcher at position `x`: - if facing `LEFT`, watches **all cells `< x`**; - if facing `RIGHT`, watches **all cells `> x`**. A player is considered **watched** if at least one watcher watches the player’s current cell. - **Player move:** During step `t`, each player tries to move **one cell to the right** (from `p` to `min(p+1, L-1)`), **but if the player is watched at the start of the step, the player cannot move and stays in place**. - **Watcher move:** After all players have (attempted) to move, each watcher moves one cell in its facing direction: - `LEFT`: `x = max(x-1, 0)` - `RIGHT`: `x = min(x+1, L-1)` Task: - After performing exactly **T** steps, return **how many players are at cell `L-1`**. Notes / clarifications: - Multiple players and watchers may occupy the same cell. - `flipTimes[]` may contain duplicates and is not sorted. Write a function that takes `(L, watchers, players, T, flipTimes)` and returns the count. Suggested constraints (for implementation): - `1 <= L <= 2e5` - `0 <= W, P <= 2e5` - `0 <= T <= 2e5` - `0 <= flipTimes[i] <= T-1`

Quick Answer: This question evaluates skills in discrete-event simulation, stateful time-step modeling, and range coverage by moving agents, as well as algorithmic efficiency for processing flip events and large input sizes.

Related Interview Questions

  • Solve Watcher Simulation And Integer Conversion - Hudson (medium)
  • Count People Reaching the Boundary - Hudson (easy)
  • Implement Buffer Parsers and Generic Map Class - Hudson (medium)
  • Implement Order Modification Feature - Hudson (hard)
  • Count inversions in a permutation - Hudson (medium)
Hudson logo
Hudson
Nov 2, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
6
0
Loading...

You are given a 1D line of L cells indexed 0..L-1. The end cell is L-1.

There are:

  • W watchers with initial integer positions watchers[] .
  • P players with initial integer positions players[] .
  • A time horizon T (non-negative integer, number of unit-time steps).
  • An unsorted list flipTimes[] of integer timestamps. At each timestamp t in flipTimes, all watchers reverse direction .

Movement model (discrete time):

  • Time steps are t = 0, 1, ..., T-1 .
  • Each watcher has a facing direction ( LEFT or RIGHT ). All watchers start facing LEFT at time 0 .
  • At the start of each step t , if t is in flipTimes , all watchers reverse direction.
  • Watching rule: At step t , a watcher at position x :
    • if facing LEFT , watches all cells < x ;
    • if facing RIGHT , watches all cells > x . A player is considered watched if at least one watcher watches the player’s current cell.
  • Player move: During step t , each player tries to move one cell to the right (from p to min(p+1, L-1) ), but if the player is watched at the start of the step, the player cannot move and stays in place .
  • Watcher move: After all players have (attempted) to move, each watcher moves one cell in its facing direction:
    • LEFT : x = max(x-1, 0)
    • RIGHT : x = min(x+1, L-1)

Task:

  • After performing exactly T steps, return how many players are at cell L-1 .

Notes / clarifications:

  • Multiple players and watchers may occupy the same cell.
  • flipTimes[] may contain duplicates and is not sorted.

Write a function that takes (L, watchers, players, T, flipTimes) and returns the count.

Suggested constraints (for implementation):

  • 1 <= L <= 2e5
  • 0 <= W, P <= 2e5
  • 0 <= T <= 2e5
  • 0 <= flipTimes[i] <= T-1

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Hudson•More Software Engineer•Hudson Software Engineer•Hudson Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ 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
  • Compare Platforms
  • Discord Community

Support

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

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.