← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Meta coding screen for a software engineer role, one question the whole time: implement a number validator from scratch. Seemed straightforward until I started thinking about all the edge cases.

Questions Asked (1)

Q1

Implement a function isValidNumber(s) that returns true only if the input string represents a valid number, following specific rules: optional leading sign, a mantissa with at most one decimal point and at least one digit, an optional exponent part starting with 'e' or 'E' followed by an optional sign and at least one digit, and no whitespace or special characters anywhere. Return false for inputs like 'e3', '+.', '1.2.3', '--6', '6e', and '6e-'.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I started confident and immediately regretted it.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the exact grammar rules and edge cases, then propose a deterministic finite automaton (DFA) that processes the string character by character, tracking state (sign, integer part, fraction, exponent). Implement the DFA with clear state transitions and validate the final state, ensuring all edge cases like missing digits are handled.

Pro tip: Mention that a DFA solution runs in O(n) time and O(1) space, and that it avoids the pitfalls of regex backtracking or multiple passes. Also, proactively discuss how you would test it with a comprehensive set of valid and invalid inputs.

1. Clarify requirements and edge cases

Restate the rules: optional sign, mantissa with at most one decimal point and at least one digit, optional exponent with optional sign and at least one digit, no whitespace or special characters. List examples of valid and invalid inputs to confirm understanding.

2. Design a state machine

Define states: start, sign, integer, dot, fraction, exponent, exponent sign, exponent digits. Specify transitions for digits, signs, dot, and 'e'/'E', ensuring no invalid transitions (e.g., multiple dots, missing digits).

3. Implement the DFA

Write code that iterates through each character, updates the state based on the transition table, and returns false immediately on an invalid character or transition. After the loop, return true only if the state is an accepting state (integer, fraction, or exponent digits).

4. Test with edge cases

Run through provided examples and additional cases like '0', '-0.1e-2', '.5', '5.', '1e', 'e1', '+', '-.', '1.2.3', '--6', '6e', '6e-', ' 1', '1 ', '1e+2.3'. Verify the function returns correct results.

5. Analyze complexity and trade-offs

State that the DFA approach is O(n) time and O(1) space. Compare with regex (which may be less efficient or harder to debug) and with built-in parsing (which may accept invalid formats). Highlight the clarity and control of the DFA.

Key Points to Mention

  • Deterministic finite automaton (DFA) with explicit states and transitions
  • Handling of optional signs in both mantissa and exponent
  • Ensuring at least one digit in mantissa and exponent
  • Rejection of multiple decimal points, missing digits, and invalid characters
  • Time and space complexity: O(n) time, O(1) space
  • Comparison with regex and built-in parsing methods, emphasizing control and efficiency

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.