The initial task involved implementing a pricing function with different pizza sizes, toppings, and an optional premium crust.
The more interesting part came afterward, when the interviewer asked how I would turn the function into a real application for a pizza shop and whether the pricing logic should be exposed through a microservice. The discussion focused on clean code, input validation, testability, user experience, and making reasonable architectural trade-offs rather than introducing unnecessary complexity.
Interview Details
Coding Round: Calculate Pizza Prices
Problem Description
The interviewer asked me to implement a function that calculates the total price of a pizza based on its size, number of toppings, and whether the customer selects a premium crust. The function signature was:
Input:
size = "extra_large"
toppings = ["cheese"]
premium_crust = True
Output:
None
Explanation:
The pizza size is not supported.
The function returns None without calculating a price.
Input:
size = "extra_large"
toppings = ["cheese"]
premium_crust = True
Output:
None
Explanation:
The pizza size is not supported.
The function returns None without calculating a price.
Part 1 — Coding Implementation
I used a dictionary to store the base prices for each pizza size, rather than writing separate conditional statements for every option. This made the implementation easier to read and maintain. If the restaurant changed its pricing later, the base prices could be updated in one place. The implementation was: