Count Number Of Ones

Ninja has an integer ‘N’. Ninja is fond of digit ‘1’ so Ninja wants to know the number of 1s in each number from 0 to N.

Your task is to help the Ninja in finding out the number of ones from 0 to ‘N’.

Input Format
The first line of input contains an integer ‘T’ denoting the number of test cases. 

The first and only line of the test case consists of a single integer ‘N’.
Output Format
Return the total number of one digit.
Constraints
1 <= ‘T’ <= 11
1 <= ‘N’ <= 5000

Time Limit: 1 sec
Note:
 You do not need to print anything, it has already been taken care of. Just implement the given function.
AnswerBot
1y

The task is to count the number of occurrences of the digit '1' in each number from 0 to N.

  • Iterate through each number from 0 to N

  • Convert each number to a string

  • Count the number of occurrences of the ...read more

Help your peers!
Add answer anonymously...
Novartis Full Stack Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter