Imagine you have two long lists of numbers, let’s call them a and b, and they are exactly the same length. Your goal is to find special pairs of positions, (i, j), where i is smaller than j, and something interesting happens between the numbers at these positions. For each pair, you’re looking for this magical balance: When you take the number from list a at position i and subtract the number from list b at position j, it should be equal to what you get when you take the number from list a at position j and subtract the number from list b at position i. Your task is to figure out how many such special pairs exist in these two lists.
Examples
01 · Example 1
a = [2, -2, 5, 3] b = [1, 5, -1, 1] return = 6
see the problem source section below for the original explanation ;)
Constraints
🍇🍇More Roblox problems
- Candy Crush Grid Matching and GravityPHONE SCREEN · Seen Jun 2026
- Closest Binary Search Tree Value VariantPHONE SCREEN · Seen Jun 2026
- Design Search Autocomplete SystemPHONE SCREEN · Seen Jun 2026
- Find the Closest PalindromePHONE SCREEN · Seen Jun 2026
- Grid Pathfinding with Obstacles (DFS)PHONE SCREEN · Seen Jun 2026
- Maximize Distance to Closest PersonPHONE SCREEN · Seen Jun 2026
- Maximum Number of Balls in a BoxPHONE SCREEN · Seen Jun 2026
- Meeting Rooms IIPHONE SCREEN · Seen Jun 2026
public int validPairs(int[] a, int[] b) {
// write your code here
}
a[2, -2, 5, 3]
b[1, 5, -1, 1]
expected6
sign in to submit