3536. Maximum Product of Two Digits ¶ Time: $O(n)$ Space: $O(n)$ C++JavaPython 1 2 3 4 5 6 7 8 9class Solution { public: int maxProduct(int n) { string s = to_string(n); ranges::sort(s); const int sz = s.length(); return (s[sz - 1] - '0') * (s[sz - 2] - '0'); } }; 1 2 3 4 5 6 7 8class Solution { public int maxProduct(int n) { char[] s = String.valueOf(n).toCharArray(); Arrays.sort(s); final int sz = s.length; return (s[sz - 1] - '0') * (s[sz - 2] - '0'); } } 1 2 3 4class Solution: def maxProduct(self, n: int) -> int: s = sorted(str(n)) return int(s[-1]) * int(s[-2]) Was this page helpful? Thanks for your feedback! Thanks for your feedback! Help us improve this page by using our feedback form.