[LeetCode] Equal Score Substrings

3707. Equal Score Substrings

You are given a string s consisting of lowercase English letters.

The score of a string is the sum of the positions of its characters in the alphabet, where 'a' = 1, 'b' = 2, …, 'z' = 26.

Determine whether there exists an index i such that the string can be split into two non-empty \substrings** s[0..i] and s[(i + 1)..(n - 1)] that have equal scores.

Return true if such a split exists, otherwise return false.

1
2
3
4
5
6
7
8
9
10
11
12
class Solution {
public:
bool scoreBalance(string s) {
int tot = 0, now = 0;
for(int i = 0; i < s.length(); i++) tot += s[i] - 'a' + 1;
for(int i = 0; i < s.length(); i++) {
now += s[i] - 'a' + 1;
if(now * 2 == tot) return true;
}
return false;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2025/10/13/PS/LeetCode/equal-score-substrings/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.