Simulate a Parking Kiosk That Accepts Coins and Returns Change

Last updated: November 29, 2026

Quick Overview

A parking kiosk charges a fixed price and accepts events INSERT(coin), CANCEL, and PRINT. Implement the kiosk as a state machine that returns, for each event, what it does: print a ticket with change, refund the balance, or report insufficient funds.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Easy

0

0

0 solved


A parking kiosk charges a fixed price and accepts events INSERT(coin), CANCEL, and PRINT. Implement the kiosk as a state machine that returns, for each event, what it does: print a ticket with change, refund the balance, or report insufficient funds.

A Google technical screen question about modeling a device as states and events, similar to what a Maps parking payment integration would need. The interviewer wants clear states, rejection of invalid coins, and correct change logic with a limited coin inventory.

What the Interviewer Expects
  • Name the states (IDLE, COLLECTING) and the events explicitly
  • Reject coins that are not accepted denominations
  • Compute change greedily from available inventory and refuse if impossible
  • Refund the full balance on CANCEL
  • Return a clear result for every event
Key Topics to Cover
state machine
object-oriented design
greedy change
simulation
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you handle a coin inventory where greedy change fails?
  • How would you make this thread safe for two payment inputs at once?
  • How would you add a card payment path?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Price is in cents. Accepted coins: 5, 10, 25, 100. State is IDLE when balance is zero, COLLECTING otherwise. INSERT c adds to balance. PRINT succeeds only if balance >= price and change can be mad...

High-Level Design

A small class keeps balance, inserted (list of coins this session), and inventory (coin to count). On PRINT, first add inserted coins to inventory, then try to make balance - price greedily fr...


Submit Your Answer
Markdown supported