Code RoomValidate decimal number
MediumPrep Room Coding #792

Validate decimal number

CodingAlgorithms & data structuresMid–Senior~30 min

Write a validator that decides whether a string is a well-formed decimal number under this grammar: an optional leading '+' or '-' sign, then a mantissa, then an optional exponent. The mantissa is either digits, or digits '.' digits, or digits '.', or '.' digits (at least one digit total). The exponent is 'e' or 'E', an optional sign, then one or more digits. No spaces are allowed. Return True if the entire string matches, else False. Examples that are valid: '0', '-3.14', '.5', '2.', '1e10', '+6E-9'. Invalid: '', '.', '1e', 'e3', '1.2.3', '+-1', '1e1.5'.

Implement
is_number(s: str) → bool
Examples
in["-3.14"]outtrue
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 30 min
InputExpectedGot
["-3.14"]truenot run yetsample