Sliding Window: Target Containment and Most-Repeated Window
Updated
Problem statement
You are given an integer array nums, a window size k, and an integer target.
Part 1. Return every length-k contiguous window that contains target at least once.
Part 2. Return the first length-k contiguous window containing the greatest number of occurrences of target. “First” means the smallest start index.
The executable function below implements Part 2 and returns the window itself, not its start index. If k is larger than the array length, return an empty array. If the target never appears, every valid window has count zero, so return the first window.
Function
mostRepeatedWindow(nums: int[], k: int, target: int) → int[]Examples
Example 1
nums = [3, 1, 3, 2, 3, 3, 4, 3]k = 4target = 3return = [3, 2, 3, 3]The windows starting at 2 and 4 each contain three copies of 3. The earlier window, starting at 2, is returned.
Example 2
nums = [3, 1, 1, 3, 1, 1]k = 3target = 3return = [3, 1, 1]Every length-3 window contains one copy of 3, so the first window wins.
Example 3
nums = [1, 2, 4, 5]k = 2target = 3return = [1, 2]The target is absent, so all valid windows tie at zero and the first window is returned.
Example 4
nums = [1, 3]k = 5target = 3return = []No length-5 window exists.
Constraints
1 <= nums.length <= 1000001 <= k- Values in
numsandtargetare 32-bit signed integers. - If
k > nums.length, return an empty array. - On a tie, return the earliest window.
More Roblox Onsite Interview questions
- Design Search Autocomplete SystemPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Candy Crush Grid Matching and GravityPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Topological Sort with Secondary OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Most Frequent Call Stack Per ThreadPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Count and Score Distinct Hat AssignmentsONSITE INTERVIEW · Seen Sep 2026
- Rate Limiter Sliding Window With Per-Entity LimitsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Most Frequent Call Path in Interleaved LogsONSITE INTERVIEW · Seen Aug 2026
- Grid Pathfinding with Obstacles (DFS)PHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2026
- Maximize Distance to Closest Person — Return the SeatONSITE INTERVIEW · Seen Jun 2026
- Cursor-Based Pagination Over Sorted LogsONSITE INTERVIEW · Seen May 2026
Similar questions at other companies
- Shortest Window with Required CountsOracle · ONSITE INTERVIEWOracle interview questions
- Count Zero Request ServersSalesforce · ONSITE INTERVIEWSalesforce interview questions
- High-Traffic IPs in a Sliding WindowGoogle · ONSITE INTERVIEWGoogle interview questions
- Longest Subarray with K Distinct ValuesAmazon · ONSITE INTERVIEW
- Count Equal Code Pairs Within Distance KInfosys · ONSITE INTERVIEWInfosys interview questions
- Longest Subarray with At Most Two Distinct ValuesMoody's Investors Service · ONSITE INTERVIEW
- Maximum Sum of a Unique-Element SubarrayTekion · ONSITE INTERVIEWTekion interview questions
- Invalid Transactions in Time OrderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Duplicate Transactions Within 60 SecondsCapital One · ONSITE INTERVIEWCapital One interview questions
- Sliding Window MedianNotion · ONSITE INTERVIEWNotion interview questions
Roblox interview experiences
- Roblox New Grad Early OA Tasks: 10 Experiences (Part 7 of 7)
- Roblox New Grad Engineer Rounds: 13 Experiences (Part 6 of 7)
- Roblox New Grad HackerRank OA: 18 Experiences (Part 5 of 7)
- Roblox New Grad CodeSignal Finals: 23 Experiences (Part 4 of 7)
- Roblox New Grad Games and BQ: 25 Experiences (Part 3 of 7)
- Roblox New Grad Coding Rounds: 23 Experiences (Part 2 of 7)