Increase Number Roundness
Description
Define an integer’s roundness as the number of trailing zeroes in it.
Given an integer n
, check if it’s possible to increase n
’s roundness by swapping some pair of its digits.
Example
-
For
n = 902200100
, the output should beincreaseNumberRoundness(n) = true
.One of the possible ways to increase roundness of
n
is to swap digit1
with digit0
preceding it: roundness of902201000
is3
, and roundness ofn
is2
.For instance, one may swap the leftmost
0
with1
. -
For
n = 11000
, the output should beincreaseNumberRoundness(n) = false
.Roundness of
n
is3
, and there is no way to increase it.
Input/Output
-
[execution time limit] 4 seconds (js)
-
[input] integer n
A positive integer.
Guaranteed constraints:
100 \leq n \leq 10^9
. -
[output] boolean
true
if it’s possible to increasen
’s roundness,false
otherwise.
[JavaScript (ES6)] Syntax Tips
1
2
3
4
5
6
// Prints help message to the console
// Returns a string
function helloWorld(name) {
console.log("This prints to the console when you Run Tests");
return "Hello, " + name;
}
Solution
1
2
3
4
5
6
7
8
9
10
11
12
function increaseNumberRoundness(n) {
return (
String(
Number(
String(n)
.split("")
.reverse()
.join("")
)
).indexOf("0") >= 0
);
}