FastPrepCount Equal-Offset Pairs Within an Index Distance
Problems/Count Equal-Offset Pairs Within an Index Distance

Count Equal-Offset Pairs Within an Index Distance

Google logoGoogle● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives the rule nums[i]-nums[j]=i-j and a limit on the index distance. A comment shows the trick nums[i]-i=nums[j]-j. The report is unclear about index order. Here, we use 0<=i<j and a strict distance j-i<k. Our version is about 90% the same as the reported question.

You are given an integer array nums and an integer k. Count the index pairs (i,j) that satisfy all three rules:

  • 0 <= i < j < nums.length.
  • The indices are less than k positions apart: j - i < k.
  • nums[i] - nums[j] = i - j.

Return the exact count as a signed 64-bit integer. When k <= 1, no pair qualifies.

Function

countEqualOffsetPairs(nums: int[], k: int) → long

Examples

Example 1

nums = [3,4,5,7]k = 4return = 3

The transformed values nums[i]-i are [3,3,3,4]; the first three indices form three qualifying pairs.

Example 2

nums = [1,2,3,4]k = 2return = 3

Only adjacent pairs are within strict distance two, and all share the same transformed value.

Example 3

nums = [5,5,5]k = 5return = 0

The transformed values are distinct, so no pair satisfies the equality.

Constraints

  • 0 <= nums.length <= 200000.
  • -10^9 <= nums[i] <= 10^9.
  • 0 <= k <= 10^9.

More Google Phone Screen questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
  • Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
  • Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
  • Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Compact Conversations by Unique ListingsSierra · PHONE SCREENSierra interview questions
  • Shortest Window by Distinct-Value SumOracle · PHONE SCREENOracle interview questions
  • Find Word-Multiset WindowsAmazon · PHONE SCREEN
  • Transcript Window MetricsSesame · PHONE SCREEN
  • Invalid Transactions in Time OrderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Detect Security Attacks from Network LogsFireworks AI · PHONE SCREEN
  • Smallest Range Covering Elements from K ListsSnap Inc. · PHONE SCREENSnap Inc. interview questions
  • Count Zero Request ServersSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Count Belt Sections With K Fruit Pairs (Forward Deployed Engineer)Boston Consulting Group · OABoston Consulting Group interview questions
  • Count Servers With No Requests in a Time WindowIBM · OAIBM interview questions

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public long countEqualOffsetPairs(int[] nums, int k) {
        // Write your code here.
    }
}
Checking account…