CTCI 18.4 count occurrence of 2 from 0 to n