Ad
  • Custom User Avatar

    In order to solve this kata one cannot use brute force logic. Meaning you cannot just try all possible sums of consecutive integers and check if they are equal to N. It's much better to step back and find a general pattern for all N that are true.
    What do all N that are true have in common?

    (Technically in the real world brute force is a (very poor) solution that (kinda) works, but it timing out here in this kata is a good thing. It makes you find a more elegant and faster solution.)

    See my solution with added comments if you cannot figure it out. I am aware that there are more elegant solutions out there, but I think my solution will explain why it works in an easy to understand way. Please comment if you disagree and have a better way to explain it. (I love being wrong and to learn new things).

  • Default User Avatar

    why are you using floor specifically?

  • Default User Avatar
  • Custom User Avatar

    What does the function floor do?

  • Custom User Avatar

    (Using C++) had the same, my issue was the use of sizeof(inputStr) to get the lenght of the string. sizeof() only returns a maximal count of 32, if a string was longer thant 32 characters the test cases would fail. I then switched to inputStr.length() which ended up working fine. Hope that helps.