A shipping hub scans a batch of freight tags attached to outbound packages. Each tag is a short code made only of lowercase English letters and digits. A tag that consists entirely of digits is read as its base-ten integer value (leading zeros are simply absorbed, so "007" is worth 7) and that value becomes its priority score. Any tag containing at least one letter is instead scored by how many characters it has. Given the full batch of tags, report the highest priority score that appears anywhere in the batch.
Line 1: an integer n, the number of tags.
Next n lines: each line contains one tag, a non-empty string of lowercase English letters (a-z) and digits (0-9) only.
Print a single integer: the maximum priority score among all n tags.
Example 1
Input
4 r2d2 42 007 cv9
Expected
42
Explanation
"r2d2" contains letters so its score is its length, 4. "42" is purely numeric so its score is 42. "007" is purely numeric and reads as 7 once leading zeros are absorbed. "cv9" contains letters so its score is its length, 3. The highest of {4, 42, 7, 3} is 42.
Example 2
Input
3 000 00 0
Expected
0
Explanation
All three tags are purely numeric and each reads as the integer 0, so every tag scores 0 and the maximum score in the batch is 0.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →