
removeDigits
Given an integer n
, you can remove either its first or last digit in one step. After applying this operation several times, you’ll get a number x
with a length of k
. It’s possible that the number will contain leading zeros. What is the minimal and the maximal possible value of x
that you can obtain?
Example:
-
For
n = 15243
andk = 2
, the output should beremoveDigits(n, k) = [15, 52]
.
To obtain the minimal number with a length ofk
, we can use the following sequence of operations:15243
->1524
->152
->15
;
To obtain the maximal number with a length ofk
, we can use the following sequence of operations:15243
->1524
->152
->52
. -
For
n = 123
andk = 1
, the output should beremoveDigits(n, k) = [1, 3]
.
Input/Output:
-
[execution time limit] 0.5 seconds
-
[input] integer64 n
The initial number.
10 ≤ n ≤ 1015
. -
[input] integer k
The desired length of the output number.
1 < 10k ≤ n
. -
[output] array.integer64
An array in which the first element is equal to the minimal possible number with lengthk
and the second element is equal to the maximal possible number of lengthk
.
Post Comment