Hidden treasure
Practice
4.6 (7 votes)
Hashmap
Hashing
Counting and arrangements
Data structures
Math
Arrays
1 D
Problem
48% Success 2946 Attempts 30 Points 5s Time Limit 256MB Memory 1024 KB Max Code

Alice, an aspiring cryptographer, recently discovered an ancient scroll containing a sequence of mysterious numbers. According to a legend, these numbers hold the key to unlocking a hidden treasure buried centuries ago by an enigmatic mathematician. However, deciphering the scroll requires identifying specific pairs of numbers that follow an ancient numerical pattern.

Alice is given an array of integers nums. She wants to determine how many pairs \((i,j)\) exist such that:

  • \(0≤i<j<nums.length\)
  • The sum of digits of nums[i] is equal to the sum of digits of nums[j].

She believes that the correct count of these pairs will reveal a crucial clue needed to decode the next part of the scroll. Your task is to help Alice compute this number so she can continue her quest.

Task

Return the number of special pairs to assist Alice in uncovering the hidden secret.

Function description

Complete the function solve() provided in the editor. This function takes the following two parameters and returns the required answer:

  • N: Represents the number of elements in the array

  • nums: A list of N integers

Input format

  • The first line contains a single integer N(size of the array).

  • The second line contains N space-separated integers representing the array nums.

Output format

For each test case, print the required answer on a new line.

Constraints

  • \(2 ≤ N ≤ 5*10^5\)

  • \(1 ≤ nums[i] ≤ 10^9\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
22 votes
Tags:
ArraysData StructuresMediumOne-dimensionalStandard Template Library
Points:30
64 votes
Tags:
ArraysData StructuresMediumOne-dimensionalStacks
Points:30
126 votes
Tags:
Data StructuresImplementationMediumOne-dimensionalSets