Ctrl K

The Heaviest Label

Easy
In a warehouse, every box carries a label: a string of lowercase English letters and digits. The **weight** of a label is defined like this: - if it consists of digits only, it is the decimal number it spells (leading zeros are allowed); - otherwise, it is the label's length. Given the array of labels labels, return the largest weight among them.
Example 1
labels=["box7", "12", "shelf", "009"] → 12

"box7" weighs 4 (it has letters), "12" weighs 12, "shelf" weighs 5 and "009" weighs 9. The largest is 12.

Example 2
labels=["0000", "a", "zz"] → 2

"0000" is all digits, so its weight is the number 0, not its length 4. The maximum comes from "zz": 2.

Example 3
labels=["a1b2c3", "300", "x"] → 300
Constraints
  • 1 ≤ len(labels) ≤ 100
  • 1 ≤ len(labels[i]) ≤ 9
  • labels[i] consists of lowercase English letters and digits
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsTwo Words, Closest Apart EasyOne-Row Typing EasyDinner for Two EasyPhrases with Synonyms EasyWord from a License Plate Easy
loading Python…
Input
labels=["box7", "12", "shelf", "009"]
Expected
12

Run checks the first 3 tests in your browser. Submit checks all 101 tests on the server, hidden ones included.