Maximum Value of a String in an Array - Problem
The value of an alphanumeric string can be defined as:
- The numeric representation of the string in base 10, if it comprises of digits only.
- The length of the string, otherwise.
Given an array strs of alphanumeric strings, return the maximum value of any string in strs.
Input & Output
Example 1 — Mixed String Types
$
Input:
strs = ["alic3","bob","3","4","00000"]
›
Output:
5
💡 Note:
"alic3" has mixed characters, value = length = 5. "bob" has letters, value = length = 3. "3" is digits only, value = 3. "4" is digits only, value = 4. "00000" is digits only, value = 0. Maximum value is 5.
Example 2 — All Digit Strings
$
Input:
strs = ["1","01","001","0001"]
›
Output:
1
💡 Note:
All strings contain only digits. "1" = 1, "01" = 1, "001" = 1, "0001" = 1. Maximum value is 1.
Example 3 — Large Numbers vs Length
$
Input:
strs = ["999","abcdefghijk"]
›
Output:
999
💡 Note:
"999" is digits only, value = 999. "abcdefghijk" has letters, value = length = 11. Maximum value is 999.
Constraints
- 1 ≤ strs.length ≤ 100
- 1 ≤ strs[i].length ≤ 9
- strs[i] consists of only lowercase English letters and digits.
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code