As reported: eBay Software Engineer, DSA round 2 — live coding on CodeSignal (2026): validate an Ada-style integer literal.
Write isValidAdaInteger(s) that returns whether s is a valid integer literal in one of two forms:
- Decimal: one or more decimal digits, e.g.
123. - Based:
base#digits#, wherebaseis written in decimal and is between2and16, anddigitsis one or more digits valid in that base. Digits above 9 are the lettersa–f(orA–F) for 10–15.
Underscores (_) may appear anywhere in either form as separators and are ignored.
Example 1
"123_456_789" -> true
Example 2
"16#123abc#" -> true
Example 3
"10#123abc#" -> false (a, b, c are not base-10 digits)
More examples: "2#1010#" → true; "2#102#" → false; "17#1#" → false; "16##" → false; "16#12" → false; "_" → false.
Constraints: 0 ≤ s.length ≤ 10^5; s contains printable ASCII characters.
Code runner format: one line, s as a JSON string. The harness prints true or false.
Clarifications
- Remove every underscore first, then check the form; after that, a decimal literal needs at least one digit, and a based literal needs a non-empty base and non-empty digits.
- Leading zeros are allowed (
"016#ff#"has base 16). - Nothing may follow the closing
#.