HOWMANY - Editorial

Problem Link - HOW MANY DIGITS DO I HAVE Practice Problem in 500 to 1000 difficulty problems

Problem Statement:

Write a program to obtain a number N from the user and display whether the number is a one digit number, 2 digit number, 3 digit number or more than 3 digit number.

Approach:

Conditional Checks:

  • We check the value of N:
    • If 1 <= N <= 9, it’s a one-digit number.
    • If 10 <= N <= 99, it’s a two-digit number.
    • If 100 <= N <= 999, it’s a three-digit number.
    • Otherwise, if N is greater than 999, it’s considered “More than 3 digits.”

Complexity:

  • Time Complexity: O(1) Simple conditional statements
  • Space Complexity: O(1) No extra space used.