Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Build Tetris with Starter Code
00:00
5 left

Build Tetris with Starter Code

HardPython

Problem

Build Tetris from provided starter code. The hardest requirement: the piece's fall timer normally stops while the player holds left or right, and you must synchronise it so the piece keeps descending instead of hanging in mid-air.

Asked in the onsite build task stage. The poster explains the requirement further in the comments and confirms the starter code provides the basic objects.

Implement advance_tetris_piece(state, elapsed_ms, held_keys, board_width, board_height). The state contains integer x, y, and fall_timer fields. Return a new state after applying one frame of input. Horizontal movement changes x by one cell, while gravity must always consume elapsed_ms, including when horizontal input is held. Use a 500 ms gravity interval and keep the piece inside the board.

Constraints

  • 1 <= board_width <= 10^4
  • 1 <= board_height <= 10^4
  • 0 <= state['x'] < board_width
  • 0 <= state['y'] < board_height
  • 0 <= state['fall_timer'] < 500
  • 0 <= elapsed_ms <= 10^9
  • held_keys contains zero or more of 'left' and 'right'

Function Signature

def advance_tetris_piece(state, elapsed_ms, held_keys, board_width, board_height):
Interviewer

Your question is Build Tetris with Starter Code. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.