A startup that works on voice AI.
The first interview was handwritten Python. I used my own IDE and environment, and any AI or AI suggestion was prohibited. At the time, I did not know how to turn off AI inline suggestions in VS Code, so I had no choice but to write everything in Vim.
Problem description
The problem was to process a string containing numbers and operators. It included +, -, *, /, swap, dup (duplicate), pop, and drop.
| Operator | Behavior | Boundary condition |
|---|---|---|
pop | Remove and pop the element at i=0 | The container must have at least one element; an empty container raises an Underflow error. |
drop | Remove and pop the element at i=-1 | The container must have at least one element; an empty container raises an Underflow error. |
dup | Copy the element at i=0 and insert it at i=0 | The container must have at least one element; a capacity limit may cause an Overflow. |
swap | Swap the elements at i=0 and i=1 | The container must have at least two elements; fewer than two raises an error. |
+, -, *, / | Pop the elements at i=0 and i=1, calculate, and push the result at i=0 | At least two elements are required. Division also needs a check for a zero divisor. |
Test cases
EXAMPLES: list[tuple[str, list[int]]] = [
('2 3 + .', [5]),
('5 dup * .', [25]),
('1 2 swap . .', [1, 2]),
('10 3 4 + - .', [3]),
('-5 3 + .', [-2]),
('1 . 2 . 3 . 4', [1, 2, 3]),
('99 2 3 + .', [5]),
('1 2 drop .', [1]),
('20 5 / .', [4]),
('30 3 / 4 - .', [6]),
]
I forgot to handle negative-number strings such as -5, and my program failed because of it. I have become so used to AI writing code that failing even a problem like this left me pretty speechless about myself.
Discussion
Loading comments…