Count Equal-Offset Pairs Within an Index Distance
Updated
Problem statement
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
kpositions 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) → longExamples
Example 1
nums = [3,4,5,7]k = 4return = 3The 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 = 3Only adjacent pairs are within strict distance two, and all share the same transformed value.
Example 3
nums = [5,5,5]k = 5return = 0The 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