Problem Link - Decrement OR Increment Practice Problem in 500 to 1000 difficulty problems
Problem Statement:
Write a program to obtain a number N and increment its value by 1 if the number is divisible by 4 otherwise decrement its value by 1.
Approach:
- If
N
modulo4
equals0 (N%4==0)
- add1
inN
and return it. - else subtract
1
fromN
and return it.
Complexity:
- Time Complexity: O(1)
- Space Complexity: O(1)