Tap here to switch tabs
Problem
Submissions

Problem: Least Operators to Express Number

med
30 min
Try to solve the Least Operators to Express Number problem.

Statement

Given two integers x and target, return the minimum number of operators required to construct a valid mathematical expression that evaluates to target.

The expression must satisfy the following conditions:

  • The only operand permitted is x.

  • The available operators are addition (+), subtraction (-), multiplication (*), and division (/).

  • Standard operator precedence applies, meaning multiplication and division are evaluated before addition and subtraction.

  • Parentheses are not permitted.

  • Division x / x evaluates to 11.

Constraints:

  • 2≤2 \leq x ≤100\leq 100

  • 1≤1 \leq target ≤2imes108\leq 2 imes 10^8

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Least Operators to Express Number

med
30 min
Try to solve the Least Operators to Express Number problem.

Statement

Given two integers x and target, return the minimum number of operators required to construct a valid mathematical expression that evaluates to target.

The expression must satisfy the following conditions:

  • The only operand permitted is x.

  • The available operators are addition (+), subtraction (-), multiplication (*), and division (/).

  • Standard operator precedence applies, meaning multiplication and division are evaluated before addition and subtraction.

  • Parentheses are not permitted.

  • Division x / x evaluates to 11.

Constraints:

  • 2≤2 \leq x ≤100\leq 100

  • 1≤1 \leq target ≤2imes108\leq 2 imes 10^8