Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Solve the Equation

XPChallenge Points: 20
levelLevel: Medium

You are given a string representing a linear equation with one variable x, where the equation may contain '+', '-', numbers, and terms with x.
Your task is to determine the value of x that satisfies the equation.

The result must be returned as:

  • "x=#value" → if there is exactly one integer solution

  • "No solution" → if no value of x can satisfy the equation

  • "Infinite solutions" → if every value of x satisfies it

The equation will always follow the format:
<expression> = <expression>

Example 1:

Input: equation = "2x+4=10-x"

Output: "x=2"

Explanation:

Rearranging gives 3x = 6, so x = 2.

Example 2:

Input: equation = "5x-3=5x+8"

Output: "No solution"

Explanation:

Left and right differ by constant: -3 ≠ 8.

Example 3:

Input: equation = "3x+9=3x+9"

Output: "Infinite solutions"

Explanation:

Both sides are identical.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result