FastPrepIssue Non-repeating OTPs in a Time Window
Problems/Issue Non-repeating OTPs in a Time Window

Issue Non-repeating OTPs in a Time Window

Mygate logoMygate● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Mygate onsite interview for a full-time role. The task is to generate four-digit OTPs that do not repeat during a period of time. The report leaves out the timing, how codes are picked, and the capacity rules. Here we use a time window with a fixed outcome.

Our version is about 80% the same as the reported question.

You are given request times in the integer array requestTimes, sorted from earliest to latest, and a positive integer window. Issue one four-digit integer code for each request. Codes range from 1000 through 9999.

At each request, choose the smallest available code. A code issued at time t is unavailable during the half-open interval [t, t + window) and becomes available again exactly at t + window. Every reuse starts a new interval.

Process requests with equal timestamps in their input order. Return the issued codes in request order. The request-count bound guarantees that a code is always available. An empty request list returns an empty array.

Function

issueOtps(requestTimes: int[], window: int) → int[]

Examples

Example 1

requestTimes = [0,1,2,5,6]window = 5return = [1000,1001,1002,1000,1001]

At time 5, code 1000 expires and becomes the smallest available code. Code 1001 similarly expires at time 6.

Example 2

requestTimes = [4,4,4,7]window = 3return = [1000,1001,1002,1000]

Equal-time requests receive distinct codes in input order. All three codes expire at time 7, when the smallest can be reused.

Constraints

  • 0 ≤ requestTimes.length ≤ 1000.
  • 0 ≤ requestTimes[i] ≤ 10^9.
  • requestTimes is nondecreasing.
  • 1 ≤ window ≤ 10^9.

More Mygate interview questions

  • Remove Invalid ParenthesesONSITE INTERVIEW · Seen Sep 2026
  • Employees Earning More Than Their ManagerPHONE SCREEN · Seen Sep 2026
  • Maximum Subarray SumPHONE SCREEN · Seen Sep 2026
  • Reverse a Linked ListPHONE SCREEN · Seen Sep 2026
  • Users Active in Both January and FebruaryPHONE SCREEN · Seen Sep 2026
  • Elements Occurring More Than n/3 TimesPHONE SCREEN · Seen Jan 2025
  • Frog Jump: Minimum EnergyPHONE SCREEN · Seen Jan 2025
  • Left View of a Binary TreePHONE SCREEN · Seen Jan 2025
  • Two SumPHONE SCREEN · Seen Aug 2024
  • Minimum in a Rotated Sorted ArrayPHONE SCREEN · Seen Jul 2024

Similar questions at other companies

  • Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
  • Retrieve Vectors by Cosine SimilarityHarvey · ONSITE INTERVIEWHarvey interview questions
  • Round-Robin Iterator over IteratorsBridge · ONSITE INTERVIEWBridge interview questions
  • Longest Subarray Within an Absolute-Difference LimitGoogle · ONSITE INTERVIEWGoogle interview questions
  • Minimize Total Weight After HalvingAmazon · ONSITE INTERVIEW
  • Design Hit CounterNutanix · ONSITE INTERVIEWNutanix interview questions
  • Meeting Rooms IISalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Top K Largest Values from a StreamThe D.E. Shaw Group · ONSITE INTERVIEWThe D.E. Shaw Group interview questions
  • Generate Complete Inputs for a Supplied ClassifierGeneral Motors · ONSITE INTERVIEW
All Mygate interview questionsSee Mygate hiring insights
Saved
class Solution {
    public int[] issueOtps(int[] requestTimes, int window) {
        // write your code here
    }
}
Checking account…