Problem Statement
Consider all squares of integers.
Among them, consider only those that contain no repeated digits in their base-10 representation.
Suppose we order them and number them starting from 0: the square 0 gets the index 0, the square 1 gets the index 1, the square 4 gets the index 2, and so on.
Given the int K, return the value at index K, or -1 if K is not a valid index.
Definition
- Class:
- RepeatFreeSquares
- Method:
- index
- Parameters:
- int
- Returns:
- long
- Method signature:
- long index(int K)
- (be sure your method is public)
Constraints
- K will be between 0 and 10^9, inclusive.
Examples
9
Returns: 81
The squares at indices 0 through 9 are 0, 1, 4, 9, 16, 25, 36, 49, 64, and 81.10
Returns: 169
The squares 100, 121 and 144 each contain a repeated digit (0, 1, and 4, respectively). The next square in our sequence is therefore 169.47
Returns: 6084