Skip to content

Practice Optimal Division

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#553
LeetCode Problem

Optimal Division

Problem Statement

You are given an integer array nums. The adjacent integers in nums will perform the float division. However, you can add any number of parenthesis at any position to change the priority of operations. You want to add these parentheses such the value of the expression after the evaluation is maximum. Return the corresponding expression that has the maximum value in string format. Note: your expression should not contain redundant parenthesis.

Source: Optimal Division on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

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

# Example 2

Input
nums = [2,3,4]
Output
"2/(3/4)"

Constraints

1 <= nums.length <= 10
2 <= nums[i] <= 1000
There is only one optimal division for the given input.

Related LeetCode Problems

Practice more problems similar to Optimal Division.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.