Count Index Pairs with Equal Value Offset
Updated
Problem statement
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[]) → longExamples
Example 1
arr = [4,1,2,3]return = 3The valid pairs are (1,2), (1,3), and (2,3).
Example 2
arr = [1,5,6]return = 1Only indices 1 and 2 satisfy the equation.
Example 3
arr = [0,1,2,3]return = 6Every 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