Practice problem · Coinbase · Hard

Flappy Bird: shouldJump

A bird flies right at a fixed speed through a scrolling course. One stage in Python with an AI assistant. Pro.

The problem

Background. A bird flies right at a fixed speed through a scrolling course. It falls under gravity unless it jumps, and a jump sets its upward speed for one instant. Pipes with a gap must be flown through, coins can be collected, and on some courses every jump costs one fuel while every coin refunds one. The course is a level; simulator.py plays a level frame by frame and is the rule book: read it first.

Implement FlappyAgent.should_jump(state) in strategy.py.

Every frame the simulator hands your agent a state dict (bird position and vertical velocity, the level's gravity, jump velocity and scroll speed, the pipes and coins ahead, the fuel left) and asks for True to jump or False to let gravity act. You may also return a tuple (decision, note); the note is kept in the frame trace. A fresh agent is created for every level.

A level is passed when the bird is still alive after the level's length frames. The bird dies on the ceiling (y <= 0), the floor (y >= screen_height), or a pipe (inside a pipe's horizontal span while not strictly inside its gap). Running out of fuel does not end the level by itself; the jumps it would have made are ignored.

Scoring

The public test runs the 10 levels in data/levels_public.json and passes when at least 8 of them are passed, within 6 seconds in total. The hidden test runs 20 more levels of the same kinds, with other physics constants, pipe spacings, gap heights, coin layouts and fuel budgets, about 2.4 times the public file's frames in all, and passes when at least 16 are passed, within 15 seconds in total.

Watching a level

replay.py prints a level frame by frame under your strategy: height, velocity, whether it jumped, fuel, the next gap, and your note. Ask the assistant to run it, for example replay.main(["data/levels_public.json", "3", "--last", "40"]) for the fourth public level's last forty frames. The test output names, for every level, the frame and the cause of death.

Notes

  • Pipes and coins in the state are the ones not yet passed or crossed, nearest first, at most 3 pipes and 5 coins. Their x is where they are now; they move left by speed every frame.
  • The physics constants differ between levels. Everything your strategy needs to predict the next frames is in the state.
  • The level data files are the only levels the tests use; nothing is random at test time.
  • You may import simulator from your strategy; what you get is still only the state you were handed. A level counts as passed only when the bird survived it on its own: every pipe passed and no more coins collected than the level holds.

Done when Submit goes green.

Constraints

  • Python 3.12+ standard library only
  • Time budgets: the public test's 10 levels in 6 seconds, the hidden test's 20 levels in 15 seconds, the strategy's own time included
  • Editable: strategy.py
  • Read-only: simulator.py, replay.py, data/levels_public.json, the public test in tests/

The files you get

  • Yours to edit: strategy.py.
  • Read-only: simulator.py, replay.py, tests/__init__.py.
  • Data: data/levels_public.json.
  • Tests you can read and run: tests/test_levels_public.py. Hidden tests run on Submit.

The round: an agent in the editor

The assistant here works like the one in the interview IDE. It reads your files, runs code and proposes changes, and you accept or reject each one. It doesn't volunteer ideas, so what gets built is what you asked for. Along the way the interviewer asks about your decisions, and at the end the report says what you checked and what you accepted unread.

Frequently asked, briefly answered

Is Flappy Bird: shouldJump free?

It is a Pro problem. Free plan includes one complete problem, plus the first stage of several more, so you can see how a round works before you pay.

Which company asks something like this?

Coinbase. It is modelled on Coinbase's round: Onsite "AI Enhanced Pilot" round: an in-IDE assistant and an existing service, four sub-tasks in 60 minutes (find a bug, design a feature, diagnose a production timeout, review a PR), screen-shared so the interviewer sees how you prompt and validate.

Do I bring my own AI tool?

No. The assistant is in the editor, same as in the interview IDEs at Meta, Stripe and Amazon. What you choose at Begin is the format: an agent that proposes changes you accept or reject, an answer-only assistant that can't write code, or no assistant at all.

What does the interviewer ask?

2 questions along the way about your own code, and one at the end about the whole session. A weak answer gets one follow up. The answers go into the report, which ends with a hire or no hire verdict.

Start the problem

Sign in and the problem opens where you left it. New here? An account takes a minute to create, and the Pro plan starts at the first stage of this problem.

Start this problem → Sign in

More like it: every practice problem, how Coinbase runs its AI round, the AI coding interview guide.