Please read the new rule regarding the restriction on the use of AI tools. ×

Find all numbers multiple of 3

Revision en1, by gg_ez, 2022-08-20 18:37:05

You are given a number n and digit d (d <= n <= 10). Your goal is to count all d-digit numbers including 0 to n that are divisible by 3.

The question was asked to me in a company interview and the only logic I gave was from backtracking by rearranging the digits and excluding the case where the left-most number is 0, but the interviewer didn't look much happy with my logic. Is there any better logic for these types of questions in general?

Thanks in advance.

Tags algorithms

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English gg_ez 2022-08-20 18:37:05 498 Initial revision (published)