Returns count of paths to reach ( i , j ) from ( 0 , 0 ) using at - most k turns . d is current direction d = 0 indicates along row , d = 1 indicates along column .
int countPathsUtil ( int i , int j , int k , int d ) {