LuckyTicketSubstring
SRM 380 · 2007-12-04 · by gevak
Problem Statement
A lucky ticket is an integer with exactly 2*n digits (written without leading zeroes), where the sum of the leftmost n digits is equal to the sum of the rightmost n digits.
You are given a
Constraints
- s will contain between 1 and 50 characters, inclusive.
- s will contain non-zero digits ('1'-'9') only.
"123231" Returns: 6
The entire string, 123231, is a lucky ticket because the first 3 digits sum up to 1+2+3=6, and the last 3 digits sum up to 2+3+1=6.
"74233285" Returns: 4
4233 is the longest lucky ticket here.
"986561517416921217551395112859219257312" Returns: 36
"12345678986987654321123456789359876543211234567895" Returns: 32
"1" Returns: 0
"112" Returns: 2
A lucky ticket must contain an even number of digits.
Submissions are judged against all 67 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class LuckyTicketSubstring with a public method int maxLength(string s) · 67 test cases · 2 s / 256 MB per case