Meta·Software Engineer·Onsite - Coding / Algorithms
- Given a text document, implement a word counter that handles edge cases like contractions, hyphenated compounds, numerals, Unicode, and emojis. Define your tokenization policy explicitly, then build a streaming solution for very large files. Discuss time and space complexity and provide test cases.
- Design and implement a generic Node class for a rooted tree where each node can have any number of children. Include addChild, removeChild, moveSubtree, preorder and breadth-first traversal, and a find method that returns the path from root. Enforce that cycles are impossible and discuss complexity for each operation.
- Given a string and a dictionary of valid words, determine if the string can be segmented into a sequence of dictionary words. Return a valid segmentation if one exists, or an empty result if not. Optimize for repeated queries against the same fixed dictionary and very long input strings.
- Given stock prices by day, find the buy and sell days that maximize profit with exactly one transaction and return the day indices. Then extend to at most two transactions with a mandatory one-day cooldown after each sell, plus an optional fixed fee per sell. Provide the algorithm, correctness reasoning, and complexity.
“I spent probably too long defining what a 'word' even is before writing a single line of code.”