Question
Maximize the Digit Product
You are given a small list of digits. You are allowed to increase the value of exactly one digit by 1. After performing this single operation, find the maximum possible product of all the digits.
Input
• The first line contains an integer n.
• The second line contains n space-separated digits.
• The second line contains n space-separated digits.
Output
For each test case, print the largest product possible after increasing any one digit by 1.
Example
Example 1
Input:
4
2 2 1 2
Output:
16
Explanation:
If we increase the digit 1 by 1, the array becomes:
2 2 2 2
The product becomes:
2 × 2 × 2 × 2 = 16
This is the maximum possible product.
Example 2
Input:
3
0 1 2
Output:
2
Explanation:
If we increase 0 → 1, the array becomes:
1 1 2
The product becomes:
1 × 1 × 2 = 2
This is the maximum possible product.
Input:
4
2 2 1 2
Output:
16
Explanation:
If we increase the digit 1 by 1, the array becomes:
2 2 2 2
The product becomes:
2 × 2 × 2 × 2 = 16
This is the maximum possible product.
Example 2
Input:
3
0 1 2
Output:
2
Explanation:
If we increase 0 → 1, the array becomes:
1 1 2
The product becomes:
1 × 1 × 2 = 2
This is the maximum possible product.