Valid Number
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Given a string s, return true if it is a valid number under the following grammar, and false otherwise. No whitespace is allowed anywhere.
A **valid number** is a **decimal** optionally followed by an **exponent**.
- A **decimal** is an optional sign (+ or -) followed by one of: digits ("12"), digits then a dot ("12."), digits then a dot then digits ("1.5"), or a dot then digits (".5"). It must contain at least one digit.
- An **exponent** is e or E, then an optional sign, then **one or more** digits (no dot).
So "2", "-0.1", "+3.e7", and "4E-10" are valid, while "abc", "1e", "e3", "--6", "-+3", and "99e2.5" are not.
Examples
Constraints
- `1 <= s.length <= 20`
- `s` consists of English letters, digits, `+`, `-`, or `.`
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.