FastPrepRandom Items for Two Components
Problems/Random Items for Two Components

Random Items for Two Components

Roblox logoRoblox● EasyNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Roblox new grad phone screen. The report asks how to show items at random in two components. This version models one distinct item per component, sampling without putting items back, uniform draws that you are given, numeric IDs, and limits. We chose those missing details. Our version is about 65% the same as the reported question.

Two components need item IDs to display. You are given an array items containing distinct IDs.

For this exercise, assume each component displays one item and the two components must display different items. Randomness is supplied as two integer draws so the result can be tested exactly:

  • Component 1 selects items[firstDraw], where 0 <= firstDraw < items.length.
  • Remove that selected entry from consideration, preserving the relative order of the remaining entries. Component 2 selects the entry at zero-based position secondDraw in this remaining list, where 0 <= secondDraw < items.length - 1.

Return [component1Item, component2Item]. If the two draws are independently uniform in their stated ranges, every ordered pair of distinct items is equally likely. Use the two supplied draws to choose the result; do not generate new random numbers. Return the IDs to display. You do not need a UI framework.

Function

componentItems(items: int[], firstDraw: int, secondDraw: int) → int[]

Examples

Example 1

items = [10,20,30,40]firstDraw = 1secondDraw = 1return = [20,30]

Component 1 takes 20. The remaining list is [10,30,40], whose index 1 contains 30.

Example 2

items = [5,8]firstDraw = 1secondDraw = 0return = [8,5]

After taking 8, the only remaining item is 5.

Example 3

items = [7,3,9,1]firstDraw = 2secondDraw = 0return = [9,7]

The remaining original-order list is [7,3,1], so its first item is 7.

Constraints

  • 2 <= items.length <= 1000.
  • Item IDs are distinct integers with 0 <= items[i] <= 10^9.
  • 0 <= firstDraw < items.length.
  • 0 <= secondDraw < items.length - 1.

More Roblox Phone Screen questions

  • Most Frequent Call Path From Function Trace LogsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Design Search Autocomplete SystemPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Candy Crush Grid Matching and GravityPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Implement a Rate LimiterPHONE SCREEN · Seen Oct 2026
  • Rate Limit by Multiple Request FieldsPHONE SCREEN · Seen Oct 2026
  • Topological Sort with Secondary OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Time-Aware Search AutocompletePHONE SCREEN · Seen Oct 2026
  • Most Frequent Call Stack Per ThreadPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Rate Limiter Sliding Window With Per-Entity LimitsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Closest Binary Search Tree Value — Base PracticePHONE SCREEN · Seen Jun 2026

Similar questions at other companies

  • Merchant Payout Reserve CalculatorStripe · PHONE SCREEN
  • Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREEN
  • Employee Count Median, Mean and ModeClay · PHONE SCREEN
  • Length of a Document Reached Through a Random TokenMercor · PHONE SCREEN
  • Apply Affine Array TransformationsByteDance · PHONE SCREEN
  • Exponential Backoff DelaysWonderful · PHONE SCREEN
  • One-Nearest-Neighbor Classification with Manhattan DistanceOpenAI · PHONE SCREEN
  • Recover Document Hierarchy from IndentationReducto · PHONE SCREEN
  • Average Grades per StudentHartford Financial Services · PHONE SCREEN
  • Through-Origin Linear RegressionMeta · PHONE SCREEN
See Roblox hiring insights
Saved
class Solution {
    public int[] componentItems(int[] items, int firstDraw, int secondDraw) {
        // write your code here
    }

}
Checking account…