Ctrl K

Coprime Digit Pairs

Easy
You are given an array of positive integers numbers. A pair of indices i < j is called lucky when the **first** digit of numbers[i] and the **last** digit of numbers[j] are coprime, meaning their greatest common divisor is 1. Order matters: the first digit comes from the left number of the pair, the last digit from the right one. Return the number of lucky pairs.
Example 1
numbers=[36, 15, 27] → 3

Pair (0, 1): 3 and 5 are coprime; (0, 2): 3 and 7 are too; (1, 2): 1 and 7 as well. That makes 3.

Example 2
numbers=[42, 64, 8] → 0

The leading digits are 4 and 6 and the last digits are 4 and 8, so every pair shares the factor 2 and none count.

Example 3
numbers=[19, 91] → 1
Constraints
  • 2 ≤ len(numbers) ≤ 100
  • 1 ≤ numbers[i] ≤ 9999
  • No number ends in 0
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsEven Piles of Cards EasyPhoto Frames of the Same Shape MediumPrimes Along Grid Rays MediumPair GCDs by Sorted Position HardPairs of Equal Values Easy
loading Python…
Input
numbers=[36, 15, 27]
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 69 tests on the server, hidden ones included.