Solve Parser, Trading, Tree, And Deck Tasks

Read the full interview experience this question came from →

Quick Overview

This question evaluates input validation and parsing for numeric literals, array-based algorithmic optimization for single-trade profit, tree traversal for extracting rightmost nodes per depth, and software design for a stateful card-deck with shuffle and testing.

Solve Parser, Trading, Tree, And Deck Tasks

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You will solve several independent programming tasks. For each task, implement clean, tested code and state the time and space complexity. 1. Validate a numeric literal Given a string `s`, return whether it represents a valid decimal number. After trimming leading and trailing spaces, the entire string must match this grammar: - `number := sign? (digits '.' digits? | '.' digits | digits) exponent?` - `exponent := ('e' | 'E') sign? digits` - `sign := '+' | '-'` - `digits := one or more characters from '0' to '9'` Examples that should be valid: `"0"`, `"-3.14"`, `"+.8"`, `"2e10"`, `"-1.2E-3"`. Examples that should be invalid: `"abc"`, `"1a"`, `"e9"`, `"."`, `"+"`, `"1e"`, `"--6"`. 2. Maximize profit from one trade Given an array `prices` where `prices[i]` is the price of an asset on day `i`, choose at most one buy day and one later sell day. Return the maximum possible profit. If no profitable trade exists, return `0`. 3. Return the rightmost value at each tree depth Given the root of a binary tree, return the list of node values visible when viewing the tree from the right side. For each depth, include the value of the rightmost node at that depth. 4. Implement a card deck Design and implement a small card-deck library for a standard 52-card deck. Include representations for suits and ranks, and implement operations such as `reset`, `shuffle`, `draw(n)`, and `remaining`. The deck must not produce duplicate cards before reset, and `draw(n)` should define clear behavior when fewer than `n` cards remain. Include unit tests for normal and edge cases.

Overview: This question evaluates input validation and parsing for numeric literals, array-based algorithmic optimization for single-trade profit, tree traversal for extracting rightmost nodes per depth, and software design for a stateful card-deck with shuffle and testing.

Read the full Meta Software Engineer interview experience this question came from

|Home/Coding & Algorithms/Meta
Meta logo
Meta
Apr 9, 2026
mediumSoftware EngineerOnsiteCoding & Algorithms
12
0

You will solve several independent programming tasks. For each task, implement clean, tested code and state the time and space complexity.

  1. Validate a numeric literal

Given a string s, return whether it represents a valid decimal number. After trimming leading and trailing spaces, the entire string must match this grammar:

  • number := sign? (digits '.' digits? | '.' digits | digits) exponent?
  • exponent := ('e' | 'E') sign? digits
  • sign := '+' | '-'
  • digits := one or more characters from '0' to '9'

Examples that should be valid: "0", "-3.14", "+.8", "2e10", "-1.2E-3". Examples that should be invalid: "abc", "1a", "e9", ".", "+", "1e", "--6".

  1. Maximize profit from one trade

Given an array prices where prices[i] is the price of an asset on day i, choose at most one buy day and one later sell day. Return the maximum possible profit. If no profitable trade exists, return 0.

  1. Return the rightmost value at each tree depth

Given the root of a binary tree, return the list of node values visible when viewing the tree from the right side. For each depth, include the value of the rightmost node at that depth.

  1. Implement a card deck

Design and implement a small card-deck library for a standard 52-card deck. Include representations for suits and ranks, and implement operations such as reset, shuffle, draw(n), and remaining. The deck must not produce duplicate cards before reset, and draw(n) should define clear behavior when fewer than n cards remain. Include unit tests for normal and edge cases.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...