Examples [code] [code] ----- [code] [code]
- User
Examples
+-+-+1
---3 Assistant
Example 1:
+-+-+→ Output:1- Count of
+: 3 - Count of
-: 2 - Difference: |3 - 2| = 1 ✓
Example 2:
---→ Output:3- Count of
+: 0 - Count of
-: 3 - Difference: |0 - 3| = 3 ✓
The pattern is clear: the answer is the absolute difference between the number of
+signs and-signs in the input string.Verification:
- For
+-+-+: 3 pluses and 2 minuses → |3 - 2| = 1 ✓ - For
---: 0 pluses and 3 minuses → |0 - 3| = 3 ✓
Alternative way to compute: Assign = +1 and = -1, then sum and take absolute value:
- Count of