title: Given a number n, find out how many numbers have digit 2 in the range 0...n
body: <p>It's an interview question.</p>
  
  <blockquote>
    <p>Given a number n, find out how many numbers have digit 2 in the range 0...n</p>
  </blockquote>
  
  <p>For example , </p>
  
  <blockquote>
    <p>input = 13  output  = 2  (2 and 12)</p>
  </blockquote>
  
  <p>I gave the usual O(n^2) solution but is there a better approach.</p>
  
  <p>is there any 'trick' formula that will help me to get the answer right away</p>