Validate Numeric Literals in a Config File Including Exponents

Last updated: November 29, 2026

Quick Overview

Given a string from a service config file, return True if it is a valid decimal number: an optional sign, digits with at most one decimal point (at least one digit overall), and an optional exponent of e or E followed by an optionally signed integer.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Given a string from a service config file, return True if it is a valid decimal number: an optional sign, digits with at most one decimal point (at least one digit overall), and an optional exponent of e or E followed by an optionally signed integer.

Meta's configuration systems push values to huge fleets, so a malformed number caught at validation time saves an outage. Interviewers use this problem to see whether a candidate can turn a fuzzy grammar into a precise state check without a regex crutch.

What the Interviewer Expects
  • Write the grammar before coding
  • Track seen_digit, seen_dot, seen_exp flags in one pass
  • Reject a dot after the exponent and a second exponent
  • Require digits after the exponent
  • Allow a sign only at the start or right after e
Key Topics to Cover
string parsing
finite state machine
validation
grammar
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you write this as an explicit finite automaton table?
  • How would you extend it to hex floats or underscores like 1_000?
  • How would you report the position of the first invalid character?
  • Would you trust float() here, and why not?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Valid: 2, 0089, -0.1, +3.14, 4., -.9, 2e10, -90E3, 3e+7, 53.5e93.
  • Invalid: abc, 1a, 1e, e3, 99e2.5, --6, -+3, 95a54e53, ., +.
  • No leading or trailing white...
High-Level Design

The grammar is [sign] (digits [. digits?] | . digits) [(e|E) [sign] digits]. A single pass with three flags captures it:

  • Digit: set seen_digit.
  • Sign: valid only at index 0 or right after e/...

Submit Your Answer
Markdown supported