Reported July 2026
OpenAIrecursion

Toy Language Generic Return-Type Inference

Reported by candidates from OpenAI's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live OpenAI OA. Under 2s to a working solution.
Founder's read

OpenAI reported this one in July 2026, and the detail that matters is in the signature itself: [T1, T2, int, T1] -> [T1, T2] with actuals [int, char, int, int]. It's a toy type checker. You parse a signature, match formal types against actual types, bind generics like T1 on first sight, and substitute them into the return type. Nothing exotic, but parsing nested tuples under pressure is where people burn the clock. If you blank on the parser, StealthCoder is the safety net running invisibly during the live OA. Read the pattern first, though. It's recursion plus a hash map of bindings.

The problem

A toy type language contains:
primitive types char, int, and float;
generic names made from an uppercase letter followed by digits, such as T1 and T2;
tuple types such as [int, T1, char], which may contain nested tuples;
function signatures such as [int; [int, T1]; T2] -> [char, T2, [float, float]].
Given a function signature and concrete actual parameter types, infer the concrete return type.
Match formal and actual parameter types recursively:
A primitive formal type must equal the corresponding actual type.
A tuple must match a tuple with the same number of elements, and corresponding elements must match recursively.
The first occurrence of a generic binds it to the corresponding concrete actual type.
Every later occurrence of that generic must match the same bound type.
After all parameters match, substitute the generic bindings into the return type. A fixed-type mismatch, tuple-shape mismatch, or conflicting generic binding is an error.
The outer formal-parameter list may use commas or semicolons. Return the inferred type in canonical form with comma-and-space separators inside tuples.
What the interview report shared
The onsite exercise provided Node and Function classes for the same primitive, generic, tuple, and function grammar. Its second part asked candidates to infer a return Node by substituting generic bindings and rejecting mismatches or conflicts. The report also supplied the complete valid example below. This practice function accepts the report's textual type notation directly.

Function
inferReturnType(functionSignature: String, actualParameters: String) → String

Examples
Example 1
functionSignature = "[T1, T2, int, T1] -> [T1, T2]"
actualParameters = "[int, char, int, int]"
return = "[int, char]"
T1 binds to int and its repeated occurrence is consistent. T2 binds to char. Substituting those bindings into [T1, T2] gives [int, char].

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is two clean phases. First, write a tokenizer and a recursive parser that turns type text into nodes: primitive, generic, or tuple with children. Treat commas and semicolons the same in the outer parameter list. Second, write match(formal, actual, bindings). Primitives must be equal. Tuples need equal length, then recurse pairwise. A generic either binds on first sight or must equal its stored binding, and the stored binding can be a whole nested tuple, so compare structurally. Then substitute into the return type and print with comma-and-space separators. The common pitfall is sloppy parsing: splitting on commas breaks nested tuples, so track bracket depth or use a real recursive descent. Another miss is forgetting an arity mismatch between parameter lists. If the parser stalls mid-assessment, StealthCoder is the hedge for the live OA.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Toy Language Generic Return-Type Inference cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass OpenAI's OA.

OpenAI reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Toy Language Generic Return-Type Inference FAQ

What's the core trick in the OpenAI generic return-type inference problem?+

Recursive structural matching with a hash map of generic bindings. Bind a generic the first time you see it, and check equality on every later occurrence. After all parameters match, substitute the bindings into the return type and print it in canonical form.

How hard is this really?+

The logic is easy, the parsing is the work. Nested tuples mean you can't just split on commas. If you've written a small recursive descent parser before, it's a medium. If not, the parser eats most of your time.

What counts as an error?+

Three cases: a primitive formal type that doesn't equal the actual type, a tuple matched against a different shape or length, and a generic that's already bound to a different concrete type. Decide up front how you'll signal errors, like an exception or an error string.

Can a generic bind to a nested tuple?+

Yes. A generic matches whatever concrete actual type sits in its position, including a tuple. Later occurrences must match that same bound type, so you need a deep equality check on your parsed nodes, not a reference comparison.

How do I prepare in 48 hours?+

Write the tokenizer, the recursive parser, the matcher, and the substitution and printer once each, from scratch. Test with nested tuples, repeated generics, semicolon separators, and mismatches. Aim for a clean node class so the matcher and printer stay short.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with OpenAI.

OA at OpenAI?
Invisible during screen share
Get it