Trains the technique from
LeetCode 224Basic CalculatorThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A surveyor's notebook records how much a benchmark has moved as one long offset line, for example 40-(6+9). The line is a string expr built only from digits, +, -, round brackets and spaces.
Reading rules for the line:
+ and - between two pieces add and subtract, applied left to right.- may also appear as a sign in front of a single number or a bracketed group, as in -7 or -(4+2). + is never used that way.Return the total offset the line describes. Passing the line to a language-provided expression evaluator is not allowed.
Example 1
The bracketed group is worth 11, and the minus in front of it applies to all of it, so the line reads 7 - 11.
Example 2
The group is worth -5, the leading sign flips it to 5, and the trailing 4 brings the total to 9.
Example 3
The inner groups are 15 and 4, so the outer group is 11, and subtracting 8 leaves 3.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def evaluate_offsets(expr: str) -> int:public int evaluateOffsets(String expr)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.