Decide Whether a Spreadsheet Cell Holds a Valid Numeric Literal

Last updated: November 29, 2026

Quick Overview

When a user types into a Google Sheets cell, decide whether the trimmed text is a valid number: an optional sign, digits with at most one decimal point (at least one digit overall), and an optional exponent e or E followed by an optional sign and at least one digit.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


When a user types into a Google Sheets cell, decide whether the trimmed text is a valid number: an optional sign, digits with at most one decimal point (at least one digit overall), and an optional exponent e or E followed by an optional sign and at least one digit.

A Google technical screen question where the clean answer is an explicit finite automaton rather than a pile of flags. The interviewer checks that you enumerate states, handle tricky inputs like '.', '1e', and '+.5', and can extend the grammar without rewriting the code.

What the Interviewer Expects
  • Write the grammar precisely before coding
  • Define DFA states and a transition table keyed by character class
  • List the accepting states explicitly
  • Test tricky strings: '.', 'e5', '1e', '-.5e-3', '3.'
  • Explain why a table is easier to extend than nested conditions
Key Topics to Cover
finite automaton
string parsing
state machine
validation
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
  • Extend the machine to accept thousands separators like 1,234.5.
  • Add hexadecimal literals such as 0x1F.
  • How would you return the parsed float without calling float()?
  • How would you report the position of the first invalid character?
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

Input: a string (trim surrounding spaces first). Valid: 12, -3.5, .5, 3., +6e-2, 1E10. Invalid: ., e3, 1e, 1e2.5, --1, 1 2, empty. No locale separators. Output a boolean....

High-Level Design

Character classes: sign, digit, dot, exp, anything else is invalid. States:

  • start: nothing read
  • sign: read a leading sign
  • int: digits before any dot (accepting)
  • dot_no_int: a ...

Submit Your Answer
Markdown supported