Ctrl K

Numbers and Their Mirrors

Medium
You are given an array of positive integers values. For every original number, write its digits in reverse order (leading zeros are dropped, so 300 becomes 3) and append the result to the end of the array. Only the original numbers are mirrored, not the appended ones. Return how many distinct numbers the final array contains.
Example 1
values=[47, 74, 300, 5] → 5

The array gains 74, 47, 3 and 5. The result is [47, 74, 300, 5, 74, 47, 3, 5], with five distinct numbers: 3, 5, 47, 74, 300.

Example 2
values=[121, 121] → 1

121 reads the same both ways, so only one distinct number remains.

Constraints
  • 1 ≤ len(values) ≤ 10⁵
  • 1 ≤ values[i] ≤ 10⁶
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPairs Balanced by Their Mirrors MediumPhoto Frames of the Same Shape MediumPairs Off the Pace MediumPrimes Along Grid Rays MediumCorners Made of Ones Medium
loading Python…
Input
values=[47, 74, 300, 5]
Expected
5

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