Practice Number of Beautiful Pairs
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
You are given a 0-indexed integer array nums. A pair of indices i, j where 0 <= i < j < nums.length is called beautiful if the first digit of nums[i] and the last digit of nums[j] are coprime. Return the total number of beautiful pairs in nums. Two integers x and y are coprime if there is no integer greater than 1 that divides both of them. In other words, x and y are coprime if gcd(x, y) == 1, where gcd(x, y) is the greatest common divisor of x and y.
Source: Number of Beautiful Pairs on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
nums = [2,5,1,4]
5
# Example 2
nums = [11,21,12]
2
Constraints
Related LeetCode Problems
Practice more problems similar to Number of Beautiful Pairs.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.