TheRedDevil18's blog

By TheRedDevil18, history, 5 weeks ago, In English

I am getting WA for Test Set 2.

I looked at other people's solutions and also generated some random cases on both the correct and my solution, but both are giving the same answer.

Can anyone tell where I am getting it wrong?

My code

 
 
 
 
  • Vote: I like it
  • +8
  • Vote: I do not like it

»
5 weeks ago, # |
  Vote: I like it +8 Vote: I do not like it

Try this:

1
2
99899 99

Output should be 3. Final array: 99899 99900

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    Thanks for the help. I got it.

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    I have got this case right. Also every other case i can imagine of. Still WA on 2nd test set. I did it using long long as the data type. Could that be a problem?

    • »
      »
      »
      5 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I also overflowed. Since the minimal number that is larger than the last can be one digit longer, numbers can be up to 10^n = 10^100, far exceeding long long. There's a lot of ways to get around this like using strings.

      • »
        »
        »
        »
        5 weeks ago, # ^ |
          Vote: I like it +5 Vote: I do not like it

        The numbers can only go till 10^20 or 10^21 , in the case where all the given 100 elements are 10^9

        • »
          »
          »
          »
          »
          5 weeks ago, # ^ |
            Vote: I like it +8 Vote: I do not like it

          If the list of n=100 numbers is 199, 198, ... 100, the optimal solution is 199, 1980, 19700, ... , 100...000. Where the last number has 101 zeros.

          • »
            »
            »
            »
            »
            »
            5 weeks ago, # ^ |
              Vote: I like it +2 Vote: I do not like it

            Actually an even easier case is just all numbers = 1.

            • »
              »
              »
              »
              »
              »
              »
              5 weeks ago, # ^ |
              Rev. 3   Vote: I like it +13 Vote: I do not like it

              No bro, if all numbers are 1

              Input: 1 1 1 1 1 1 1 ......(100 1s)
              Output: 1 10 11 12 13 ...19 100 101 102....
              
            • »
              »
              »
              »
              »
              »
              »
              5 weeks ago, # ^ |
                Vote: I like it +8 Vote: I do not like it

              Yah you are right on your first example, sorry, thanks

      • »
        »
        »
        »
        5 weeks ago, # ^ |
          Vote: I like it +8 Vote: I do not like it

        codicon thanks a lot!

      • »
        »
        »
        »
        5 weeks ago, # ^ |
          Vote: I like it +8 Vote: I do not like it

        codicon Thanks man. Just tried using strings and it worked. Regret the fact that I knew what may have gone wrong but still didnt change it.

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Alternatively, you can download test data also. They provide input and output for all test sets. And then you can compare exactly for which test case, your code is not working correctly.