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
nis to swap digit1with digit0preceding it: roundness of902201000is3, and roundness ofnis2.For instance, one may swap the leftmost
0with1. -
For
n = 11000, the output should beincreaseNumberRoundness(n) = false.Roundness of
nis3, 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
trueif it’s possible to increasen’s roundness,falseotherwise.
[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
);
}