Input: 23678210 Output: 8
int main() { int i = 349678; int j =0,k; while(i){ if (j < (k=(i %10))) { j = k; } i /=10; } printf("largest digit is :%d\n",j); }
C program to find and print second largest digit in the given number? (without using arrays, functions and using only one loop).
I was trying to get maximum rectangle area for a given histogram but I used brute force approach which have O(n^2) time complexity so I want some better solution using stack so that we could reduce time complexity to O(n) or O(log n ).