Description

Given an array of positive integers, add parentheses to maximize the division result. Return the expression as a string.

Examples

Input:nums = [1000,100,10,2]
Output:"1000/(100/10/2)"
Explanation:

1000*10*2/100=200.

Input:nums = [8]
Output:8
Explanation:

With only one number, no division operations are possible, so the result is just the number itself: 8.

Input:nums = [12,6,3,2]
Output:12/(6/3/2)
Explanation:

To maximize the result, the goal is to minimize what is being dividing by. By grouping (6/3/2) = 1, this gives 12/1 = 12, which is the maximum possible value.

Constraints

  • 1 ≤ nums.length ≤ 10

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!