Skip to content
Discussion options

You must be logged in to vote

We convert the integer to a string, split it into an array of digits, and then use a nested loop to compute the product of every pair of digits (ensuring we don't pair a digit with itself unless it appears twice). We track and return the maximum product found.

Approach

  • Convert the integer n to a string and then to an array of digits.
  • Initialize a variable maxProduct to 0.
  • Use two nested loops:
    • Outer loop i from 0 to len(digits)-1.
    • Inner loop j from i+1 to len(digits)-1 (to avoid duplicate pairs).
  • Compute product = digits[i] * digits[j].
  • Update maxProduct if product is larger.
  • Return maxProduct after loops.

Let's implement this solution in PHP: 3536. Maximum Product of Two Digits

<?php

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@basharul-siddike
Comment options

@mah-shamim
Comment options

mah-shamim Jul 25, 2026
Maintainer Author

Answer selected by basharul-siddike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested easy Difficulty
2 participants