CodeSignal python coding test from a recruiting agency
Published in · 3 min read · Jul 5, 2023
--
This problem appeared in an online coding test hosted in CodeSignal. I was talking to a recruiting agency. To measure the competency of my python skill, they gave me this coding test with three coding problems. Out of three, this one was most interest. So let me know the problem statement first and then I will analyze my approach to solve it.
Problem statement
Given an array of integers a, your task is to count the number of pairs i and j (where 0 ≤ i ≤ j < a.length), such that a[i] and a[j] are digit anagrams.
Two integers are considered to be digit anagrams if they contain the same digits. In other words, one can be obtained from the other by rearranging the digits (or trivially, if the numbers are equal). For example, 54275 and 45572 are digit anagrams, but 321 and 782 are not (since they don’t contain the same digits). 220 and 22 are also not considered as digit anagrams, since they don’t even have the same number of digits.
Example
For a = [25, 35, 872, 228, 53, 278, 872] the output should be solution(a) = 4
There are 4 pairs of digit anagrams:
- a [1] = 35 and a [4] = 53 ( i= 1 and j = 4 ),