Count all digits of a number

Beginner Problems Basic Maths Easy
  • This simple programming problem teaches you how to work with integers at a deep level, essential knowledge for many aspects of computing
  • For example, in video games, a similar concept is used to calculate scores or health points, which involve lots of operations with integers
  • Also, in data analysis software or ETL (Extract, Transform, Load) processes, the size and format of figures need to be manipulated and processed, which requires deep understanding and competence in handling numbers and digits

You are given an integer n. You need to return the number of digits in the number.


The number will have no leading zeroes, except when the number is 0 itself.

Examples:

Input: n = 4

Output: 1

Explanation: There is only 1 digit in 4.

Input: n = 14

Output: 2

Explanation: There are 2 digits in 14.

Input: n = 234

Constraints

  • 0 <= n <= 5000
  • n will contain no leading zeroes except when it is 0 itself.

Company Tags

TCS Cognizant Accenture Infosys Capgemini Wipro IBM HCL Tech Mahindra MindTree