Ad
  • Custom User Avatar

    Your solution has more than one problem:

    • The line c = sizeof arr / sizeof arr[0]; is wrong. It;s not how you get a size of a vector, and it returns wrong results.
    • Your solution works incorrectly if the input contains zeors. What does it return for following input: {1, 3, 0} ?
    • Your solution compiles with a warning, which points to an actual problem and even tells you why it crashed:
    In file included from main.cpp:6:
    ./solution.cpp:63:1: warning: control may reach end of non-void function [-Wreturn-type]
    }
    ^
    1 warning generated.
    solution.cpp:7:5: runtime error: execution reached the end of a value-returning function without returning a value
    

    You need to fix this bug. It's not a kata issue.

  • Custom User Avatar

    Please use proper code formatting when posting blocks of code.