You will solve several independent programming tasks. For each task, implement clean, tested code and state the time and space complexity.
-
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".
-
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.
-
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.
-
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.