human
Find the most frequent digit without using array / string | Simple function to count occurrences of digit d in x.
count = 0.
Initialize count of digit d.
Increment count if current digit is same as d.
Returns the max occurring digit in x.
Handle negative number.
Traverse through all digits.
Count occurrences of current digit.
Update max_count and result if needed.
Driver Code"
How can the above be solved in Python?
 ... Give me a code to find the most frequent digit without using array / string and the other steps required?
assistant
#Here is code to find the most frequent digit without using array / string and the other steps required.
 def countOccurrences ( x , d ) :
	while ( x ) :
		if ( x % 10 == d ) :
			count += 1 ;
		x = int ( x / 10 ) ;
	return count ;
def maxOccurring ( x ) :
	if ( x < 0 ) :
		x = - x ;
	for d in range ( 10 ) :
		count = countOccurrences ( x , d ) ;
		if ( count >= max_count ) :
			max_count = count ;
			result = d ;
	return result ;
x = 1223355 ;
print ( " Max ▁ occurring ▁ digit ▁ is " , maxOccurring ( x ) ) ;