DECINC - Editorial

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 modulo 4 equals 0 (N%4==0) - add 1 in N and return it.
  • else subtract 1 from N and return it.

Complexity:

  • Time Complexity: O(1)
  • Space Complexity: O(1)