PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates array manipulation, counting and efficient algorithm design—focusing on the sliding-window technique for detecting and quantifying target occurrences in fixed-size subarrays, and it measures algorithmic efficiency and complexity reasoning.

  • medium
  • Roblox
  • Coding & Algorithms
  • Machine Learning Engineer

Find target-heavy sliding windows

Company: Roblox

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Given an integer array `nums`, an integer `target`, and a fixed window size `k`, solve the following two tasks: 1. Return all contiguous subarrays of length `k` that contain at least one occurrence of `target`. 2. Among all contiguous subarrays of length `k`, return the first window that contains the maximum number of occurrences of `target`. If no length-`k` window contains `target`, return an empty list for part (1) and indicate that no valid window exists for part (2). Aim for an efficient sliding-window solution.

Quick Answer: This question evaluates array manipulation, counting and efficient algorithm design—focusing on the sliding-window technique for detecting and quantifying target occurrences in fixed-size subarrays, and it measures algorithmic efficiency and complexity reasoning.

Given nums, target, and window size k, return [all_windows_with_target, first_window_with_max_target_count]. If no length-k window contains target, return [[], None].

Constraints

  • Windows are contiguous and have length k
  • The best window is the earliest one among ties

Examples

Input: ([1, 2, 3, 2, 2], 2, 3)

Expected Output: [[[1, 2, 3], [2, 3, 2], [3, 2, 2]], [2, 3, 2]]

Input: ([1, 1, 1], 2, 2)

Expected Output: [[], None]

Input: ([5], 5, 1)

Expected Output: [[[5]], [5]]

Input: ([1, 2], 1, 3)

Expected Output: [[], None]

Hints

  1. Maintain the count of target in the current window as it slides by one position.
Last updated: Jun 27, 2026

Loading coding console...

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.

Related Coding Questions

  • Find Windows Containing a Target - Roblox (medium)
  • Implement Sliding-Window Rate Limiter - Roblox (medium)
  • Find most frequent call path in logs - Roblox (medium)
  • Track Highest-Earning Experience - Roblox (medium)
  • Find the Most Frequent Log Call - Roblox (easy)