Solve the Equation
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given a linear equation in one variable x as a string, for example "x+5-3+x=6+x-2". Each side of the = is a sum of terms joined by + or -. A term is either a non-negative integer (like 12) or an optional non-negative integer coefficient followed by x (like x, 3x, or 0x). The first term on either side may start with a -.
Return:
- "x=#" where # is the value of x, if the equation has exactly one solution (it is guaranteed to be an integer),
- "No solution" if no value of x works,
- "Infinite solutions" if every value of x works.
Examples
Constraints
- `3 <= equation.length <= 1000`
- `equation` contains exactly one `=`
- Terms are integers without leading zeros, optionally followed by `x`, joined by `+` or `-`
- If the equation has a unique solution, it is an integer with absolute value at most `1000`
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.