FastPrepRequest Retry Count
Problems/Request Retry Count

Request Retry Count

IBM logoIBM● EasyNEW GRADOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

An integer gap defines the maximum allowed time difference, in seconds, to consider a retry.

Two arrays are provided:

  • requestIds, where each element represents the request ID of a log
  • timestamps, where each element represents the time of the corresponding log, sorted in non-decreasing order

A retry occurs when two consecutive logs for the same request ID have a time difference of at most gap.

Compute the total number of retries across all request IDs and return the result.

Function

getRetryCount(gap: int, requestIds: String[], timestamps: int[]) → int

Examples

Example 1

gap = 10requestIds = ["r1", "r1", "r1", "r2", "r2"]timestamps = [100, 105, 200, 300, 302]return = 2

The table below shows the total number of retries for each request ID:

Request Retry Table
Request IDTimestampsRetry PairsRetry Count
r1[100, 105, 200](100, 105)1
r2[300, 302](300, 302)1

The total number of retries = 1 + 1 = 2.

Hence, the answer is 2.

Constraints

  • 1 ≤ gap ≤ 10^9
  • 1 ≤ n ≤ 2 * 10^6
  • 0 ≤ timestamps[i] ≤ 10^9

More IBM Online Assessment questions

  • Missing IntervalsOA · Seen Nov 2026
  • Count Peaks and ValleysOA · Seen Nov 2026
  • Last Object Exit TimeOA · Seen Nov 2026
  • Count Strictly Increasing Contiguous WindowsOA · Seen Nov 2026
  • Total Each Letter's Count in an Encoded StringOA · Seen Nov 2026
  • Count Servers With No Requests in a Time WindowOA · Seen Nov 2026
  • Maximum Easy Tasks After RearrangingOA · Seen Nov 2026
  • Tree Pythagorean TriplesOA · Seen Oct 2026
  • Minimum Power-of-Two Removal OperationsOA · Seen Oct 2026
  • Maximum Compatible Time WindowsOA · Seen Oct 2026

Similar questions at other companies

  • Build the Task HierarchyPendo · OA
  • Count User Mentions in Chat MessagesRamp · OARamp interview questions
  • Count Valid Square PairsAuxoAI · OA
  • Two SumAmazon · OA · PHONE SCREEN
  • Find Words That Can Be Formed by CharactersTabaPay · OA
  • Basic Item DiscountsPalantir · OAPalantir interview questions
  • Word Frequency Counts in Alphabetical OrderAbridge · OAAbridge interview questions
  • Customer Signer ScreeningState Farm · OA
  • Minimum Magic Stones After MergesElevenLabs · OAElevenLabs interview questions
  • K Most Recent Unique Request IDsMicrosoft · OAMicrosoft interview questions

IBM interview experiences

  • IBM Full-Time SWE OA Questions: 1 Experience
  • IBM Software Intern Résumé Rounds: 2 Experiences (Part 3 of 3)
  • IBM Intern Blitz Interviews: 23 Experiences (Part 2 of 3)
  • IBM Software Intern Interviews: 44 Experiences (Part 1 of 3)
  • IBM Software Intern Interview Questions: 15 Experiences
All IBM interview questionsSee IBM hiring insights
Saved
class Solution {
    public int getRetryCount(int gap, String[] requestIds, int[] timestamps) {
      // write your code here
    }

}
Checking account…