Skip to main content
All Questions

Parse a spec that chains tasks serially with commas and in parallel with braces and semicolons, and output every nested call expression it expands to.

Unlock detailed company stats for this questionUpgrade
A workflow system composes tasks. Each task is a function whose first argument is its input, followed by optional positional and keyword arguments, and it returns a value of the same type as its input. A specification string, in which whitespace is ignored, says how to chain tasks. Tasks separated by commas run in series, so a,b,c becomes c(b(a(input))). Tasks separated by semicolons inside curly braces run in parallel and give one code path each, so a,{b;c} becomes b(a(input)) and c(a(input)). An empty task is allowed inside braces and leaves the expression unchanged, so a,{b;} becomes b(a(input)) and a(input). Commas never separate tasks inside braces. A task's own arguments follow its name in parentheses and are placed after the input, so a('x',k=1),b(2) becomes b(a(input,'x',k=1),2). Several brace groups in series multiply out, so {a;b},{c;d} gives four code paths. Given a specification, output every resulting expression.

Community answers

No answers contributed by the community yet.

Related courses

Course

Behavioral Interviews: A Practical Guide for Engineers

Get offers at the level you deserve. Prep for senior+ behavioral interviews at FAANG and Tier-1 companies. Made with staff and principal engineers from Meta, Netflix, Google, and more. Avoid downleveling, elevate past projects, and stop sounding like a robot.

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.