BackmediumArrays PayPal

Galaxy Expedition Solution

Problem Statement

Given an array of planetary coordinates, find all pairs of spacecraft indices (i, j) that have the same coordinates and i < j. Return the count of such pairs.

Example 1
Input
[[1, 2], [2, 1], [3, 4], [4, 3]]
Output
1

Explanation: Step-by-step: First, we sort the array of arrays based on the first element of each sub-array. Then, we iterate through the sorted array and compare each sub-array with the next one. If we find a pair of sub-arrays with the same coordinates, we increment the count. Finally, we return the count of such pairs.

Example 2
Input
[[1, 2], [2, 1], [3, 4], [4, 3], [5, 6]]
Output
1

Explanation: Step-by-step: First, we sort the array of arrays based on the first element of each sub-array. Then, we iterate through the sorted array and compare each sub-array with the next one. If we find a pair of sub-arrays with the same coordinates, we increment the count. Finally, we return the count of such pairs.

Constraints

  • 1 <= array length <= 10^5
  • -10^9 <= coordinate value <= 10^9
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free