Maximum Value of a String in an Array

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.

Example 1
Inputstrs = ["alic3","bob","3","4","00000"]
Output5
"alic3" has value 5 by length, "bob" has value 3 by length, "3" has value 3, "4" has value 4, and "00000" has value 0, so the maximum value is 5.
Example 2
Inputstrs = ["1","01","001","0001"]
Output1
Each string in the array has numeric value 1, so the maximum value is 1.

Constraints

  • 1 <= strs.length <= 100
  • 1 <= strs[i].length <= 9
  • strs[i] consists of only lowercase English letters and digits.

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate