**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 be

`increaseNumberRoundness(n) = true`

.One of the possible ways to increase

*roundness*of`n`

is to swap digit`1`

with digit`0`

preceding it:*roundness*of`902201000`

is`3`

, and*roundness*of`n`

is`2`

.For instance, one may swap the leftmost

`0`

with`1`

. - For
`n = 11000`

, the output should be

`increaseNumberRoundness(n) = false`

.*Roundness*of`n`

is`3`

, and there is no way to increase it.

**Input/Output**

**[time limit] 3000ms (cs)**

**[input] integer n**A positive integer.

*Constraints:*

`100 ≤ n ≤ 10`

.^{9}**[output] boolean**`true`

if it’s possible to increase`n`

‘s roundness,`false`

otherwise.

**Tests:**

**Solution:**

bool increaseNumberRoundness(int n) { bool gotToSignificant = false; while (n > 0) { if (n % 10 == 0 && gotToSignificant) { return true; } else if (n % 10 != 0) { gotToSignificant = true; } n /= 10 ; } return false; }

Advertisements

it doesn’t work dude

LikeLike

Where is it wrong? It’s passed the all tests

LikeLike

WTF? test 5.. why expected true?

Input:

n: 106611

Output:

false

Expected Output:

true

Console Output:

Empty

LikeLike

We have the last number 1 not equal 0 and we have a zero before the number 1. So the expected result is true

LikeLike

It does work guys. Remember it’s in C++. I suspect those that say it doesn’t attempted to use it in Javascript or similar languages.

If that’s the case don’t forget to use Math.floor() to keep ‘n’ rounded down.

Javascript – Line 9:

n = Math.floor(n / 10 );

LikeLiked by 1 person