gg_ez's blog

By gg_ez, history, 2 years ago, In English

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.

  • Vote: I like it
  • 0
  • Vote: I do not like it