Ad
  • Default User Avatar

    I considered that before, but then it would lose some of the "spice" in the question. I wanted to get some number theory in the problem, but since I'm not a mathematician, it's hard for me to get correct answers eg. if you add up all postive and negative integers would it be 0 or NaN?

    ZED.CWT, your approach makes sense but my approach makes sense as well, like I said I'm not a mathematician either so I'm not sure which one is correct.

    I added in the description to return NaN if all integers would work as n to clear things up(and make things a little more boring).

  • Default User Avatar

    Correct me if I am wrong

  • Default User Avatar

    For both cases, new int[]{} and new int[]{x}, any integer would be able to work as n to satisfy the requirements. This means that we have to take the sum of all integers ranging from negative infinity to postive infinity. Taking the sum of all postive integers is postive infinity. Likewise, taking the sum of all negative integers is negative infinity. Postive infinity plus negative infinity is indeterminate, so NaN would best represent that.

  • Default User Avatar

    Fixed it.

  • Default User Avatar

    Interesting! Very nice!

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution