submission link(CodeChef: Practical coding for everyone)
Your code will fail in test case
1
4
1 0 1 1
Here answer should be 1300 as
- 2nd month → 1100 (Rent + Late fees) +
- 3rd month → 100 (As a late fees) +
- 4th month → 100 (As a late fees) == 1300, but in your case it’s 1200
What you are missing is that if we ever encounter a zero, all the months will be affected by it even if all are 1’s. so you can’t decrement like
zero--
in your code.
Hope this helps
Thank you
1 Like
remove
zero-- ;
from your code
for eg,
if input is
1
3
0 1 1
answer must be 1300 but your code gives 1200