Back to July Back to Year 2026
EASY 25 Jul 2026 View on LeetCode

3536. Maximum Product of Two Digits

</> Solution

/**
 * Problem: LeetCode 3536 - Maximum Product of Two Digits
 * Difficulty: Easy
 * Language: Java
 * Author: CodeByTushu
 */
class Solution {
    public int maxProduct(int n) {
        int first = 0;
        int second = 0;
        while (n > 0) {
            int digit = n % 10;
            if (digit >= first) {
                second = first;
                first = digit;
            } else if (digit > second) {
                second = digit;
            }
            n /= 10;
        }
        return first * second;
    }
}

TIME COMPLEXITY

O(log10(N))

SPACE COMPLEXITY

O(1)

TOPICS

Greedy Math Sorting