FastPrepCount Index Pairs with Equal Value Offset
Problems/Count Index Pairs with Equal Value Offset

Count Index Pairs with Equal Value Offset

Google logoGoogle● EasyINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A firsthand Google Software Engineer internship report from July 2025 gives the exact equation arr[i] - arr[j] = i - j and asks for the number of index pairs. We rebuilt the rule that each pair counts once with i < j, the input limits, and the return type. Our version is about 92% the same as the reported question.

Given an integer array arr, return the number of index pairs (i, j) such that 0 <= i < j < arr.length and arr[i] - arr[j] = i - j.

Function

countMatchingIndexPairs(arr: int[]) → long

Examples

Example 1

arr = [4,1,2,3]return = 3

The valid pairs are (1,2), (1,3), and (2,3).

Example 2

arr = [1,5,6]return = 1

Only indices 1 and 2 satisfy the equation.

Example 3

arr = [0,1,2,3]return = 6

Every pair satisfies the equation because arr[i] - i is always zero.

Constraints

  • 0 <= arr.length <= 200000.
  • -1000000000 <= arr[i] <= 1000000000.

More Google Onsite Interview questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Majority ElementMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Net Position Calculation from API SnapshotsHeadlands Technologies · ONSITE INTERVIEWHeadlands Technologies interview questions
  • Square Each Array ValueAMD · ONSITE INTERVIEWAMD interview questions
  • Max Points on a LineLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • Group-Relative Policy AdvantagesAmazon · ONSITE INTERVIEW
  • Product Total With the Cheapest PromotionInstacart · ONSITE INTERVIEWInstacart interview questions
  • Equation Tuple CombinationZoox · ONSITE INTERVIEW
  • Unique Near-Equal Target-Sum PairsFivetran · ONSITE INTERVIEWFivetran interview questions
  • Minimum Unique Card Suffix LengthBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Count Pairs Divisible by KApple · ONSITE INTERVIEWApple interview questions

Interview reports that mention this question

  • Google SWE Intern OA and Interviews: 42 Experiences (Part 1 of 3)
  • Google India SWE Intern Interview Questions: 8 Experiences

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
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public long countMatchingIndexPairs(int[] arr) {
        // Write your code here.
    }
}
Checking account…