Original problem · C++ solution
Reset a counter for every test case and add one for each positive value with remainder one modulo two.
Reset a counter for every test case and add one for each positive value with remainder one modulo two.
- Time: O(total N).
- Extra space: O(1).
Parenthesize conditional expressions sent to an output stream so the stream insertion operator does not change their grouping. Use separate variables for quantities with different roles.
Check whether the condition is strict or inclusive, particularly at the smallest and largest permitted values.
State the invariant without looking at the code. Give one input that breaks the most tempting incorrect approach, then add it to the tests.