LuckySum
SRM 665 · 2015-06-30 · by tehqin
Problem Statement
A lucky number is a positive integer such that each of its digits is a 4 or a 7. A lucky sum is the sum of two (not necessarily distinct) lucky numbers. Cat loves lucky sums!
Cat has a
Find and return the smallest lucky sum that matches note. If there are no lucky sums that match note, return -1.
Constraints
- note will contain between 1 and 14 characters, inclusive.
- Each character of note will be either a digit ('0'-'9') or a question mark ('?').
- The first character of note will not be '0'.
- At least one character of note will be '?'.
"?" Returns: 8
4+4=8, which is the smallest lucky sum.
"?1" Returns: 11
4+7=11
"4?8" Returns: 448
4+444=448
"2??" Returns: -1
The numbers that match this note are the numbers 200 through 299. None of these numbers is a lucky sum.
"??????????????" Returns: 11888888888888
Submissions are judged against all 203 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class LuckySum with a public method long long construct(string note) · 203 test cases · 2 s / 256 MB per case