Tap here to switch tabs
Problem
Submissions

Problem: Count Nice Pairs in an Array

med
30 min
Try to solve the Count Nice Pairs in an Array problem.

Statement

You are given an array of non negative integers nums.

Let rev(x) be a function that reverses the digits of a non negative integer x. For example, rev(123123) == 321321, and rev(120120) == 2121.

A pair of indices (i, j) is considered nice if:

  • 0≤0 \leq i << j << nums.length

  • nums[i] ++ rev(nums[j]) == nums[j] ++ rev(nums[i])

Return the total number of nice pairs. Since the answer may be very large, return it modulo 109+710^9 + 7.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 0≤0 \leq nums[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count Nice Pairs in an Array

med
30 min
Try to solve the Count Nice Pairs in an Array problem.

Statement

You are given an array of non negative integers nums.

Let rev(x) be a function that reverses the digits of a non negative integer x. For example, rev(123123) == 321321, and rev(120120) == 2121.

A pair of indices (i, j) is considered nice if:

  • 0≤0 \leq i << j << nums.length

  • nums[i] ++ rev(nums[j]) == nums[j] ++ rev(nums[i])

Return the total number of nice pairs. Since the answer may be very large, return it modulo 109+710^9 + 7.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 0≤0 \leq nums[i] ≤109\leq 10^9