← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Meta SWE coding round, one question on string parsing. Pretty straightforward on the surface but there are enough edge cases to trip you up if you're not careful.

Questions Asked (1)

Q1

Given a string, write a function to determine whether it represents a valid number. Valid numbers include integers and decimals like '123', '4.56', or '-78.9'. Strings like '123abc' or '--6' should return false.

Algorithms & Data Structures
Author's notes

The basic cases are easy but the edge cases pile up fast.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the exact definition of a valid number (e.g., leading/trailing spaces, scientific notation, leading zeros) and then implement a deterministic finite automaton (DFA) that processes the string character by character. Alternatively, use a well-structured regex, but be prepared to explain its components and edge cases.

Pro tip: At Meta, interviewers value clean, maintainable code and thorough edge-case handling. Start by writing a clear state machine on the whiteboard, then translate it to code—this shows systematic thinking and reduces bugs.

1. Clarify requirements

Ask the interviewer about the exact definition of a valid number: Are leading/trailing spaces allowed? Is scientific notation (e.g., '1e10') considered valid? Are leading zeros allowed? This ensures you solve the right problem.

2. Choose an approach

Decide between a regex and a state machine. A regex is concise but can be hard to explain; a state machine is more verbose but demonstrates algorithmic thinking and is easier to extend.

3. Design the state machine

Define states such as start, sign, integer, dot, fraction, and accept. Map transitions for digits, signs, dots, and possibly exponent characters. Ensure you handle edge cases like a lone sign or multiple dots.

4. Implement and test

Write the code based on the state machine, then walk through test cases: valid numbers (e.g., '123', '-4.56'), invalid ones (e.g., '123abc', '--6'), and edge cases (e.g., '.', '-.', '1.2.3').

5. Analyze complexity

State that the time complexity is O(n) and space complexity is O(1) for the state machine approach, as it processes each character once with constant extra space.

Key Points to Mention

  • Edge cases: empty string, single sign, multiple dots, leading/trailing spaces, leading zeros, and scientific notation.
  • State machine design: states and transitions for digits, signs, dots, and exponent characters.
  • Time and space complexity: O(n) time and O(1) space for the state machine approach.
  • Comparison of regex vs. state machine: regex is concise but may be less readable; state machine is more explicit and easier to debug.
  • Handling of optional characters: e.g., a sign is optional but must be followed by a digit or dot.
  • Testing strategy: include both valid and invalid inputs, and walk through them during the interview.

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