← Ziphq Interview Insights

Ziphq·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Ziphq SWE interview dropped me into an existing vending machine OOD and asked me to bolt on change-making logic. More nuanced than it sounds once you start thinking about inventory constraints.

Questions Asked (2)

Q1

Given a vending machine with an existing product/inventory and bill-insertion subsystem, implement the change-making logic after a successful purchase. How do you decide between a greedy approach and an optimal DP-based strategy, and what do you do when exact change is impossible?

Algorithms & Data StructuresSystem DesignTechnical Trade-offs
Author's notes

I went greedy first because it's the obvious move, largest denomination down.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the constraints: coin denominations, inventory limits, and whether the goal is to minimize coins dispensed or preserve certain denominations. Then compare greedy vs DP: greedy is simple and fast but only optimal for canonical systems, while DP guarantees optimality but costs more time/space. Finally, address the impossible-change scenario with a clear fallback policy (e.g., cancel transaction, offer credit, or exact-change-only mode).

Pro tip: Mention that real vending machines often use a hybrid: greedy for common cases and DP as a fallback when greedy fails or when inventory is constrained. Also note that the 'optimal' solution might prioritize keeping a healthy mix of coins for future transactions, not just minimizing coins for the current one.

1. Clarify requirements and constraints

Ask about coin denominations, whether the machine can dispense coins, inventory limits, and business rules (e.g., must return exact change or can it give credit).

2. Compare greedy vs DP

Explain that greedy works if the coin system is canonical (e.g., US coins) and is O(n) time; DP is O(n*amount) and guarantees optimality for any system but may be overkill for typical vending machine amounts.

3. Consider inventory constraints

Note that even with a canonical system, limited coin inventory can break greedy; DP can incorporate inventory counts but becomes more complex (e.g., bounded knapsack).

4. Handle impossible change

Define fallback behavior: reject the purchase before dispensing, offer to keep the remainder as credit, or switch to exact-change-only mode until restocked.

5. Design for maintainability and testing

Suggest encapsulating the change-making strategy behind an interface so it can be swapped, and emphasize unit tests for edge cases like exact change, insufficient coins, and non-canonical denominations.

Key Points to Mention

  • Canonical coin systems: greedy is optimal for US coins but not for arbitrary denominations (e.g., {1, 3, 4}).
  • Dynamic programming: unbounded knapsack or coin change DP to minimize coins, with time O(n*amount) and space O(amount).
  • Inventory-aware change-making: track available coins and ensure the solution doesn't exceed stock; may require bounded DP or greedy with backtracking.
  • Impossible change scenarios: pre-check if change can be made before finalizing purchase; if not, cancel or offer alternatives.
  • Trade-offs: greedy is faster and simpler but may fail; DP is robust but slower and more memory-intensive; hybrid approaches balance both.
  • Real-world constraints: vending machines have limited coin tubes, so preserving certain coins for future transactions may be more important than minimizing coins now.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

How should the vending machine handle the case where it cannot make exact change with its current cash inventory? Should it reject the purchase outright or refund the inserted bills?

Technical Trade-offsSystem Design
Author's notes

This felt like a product judgment question sneaking into a coding interview.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the requirements and constraints, then compare the two options (reject vs. refund) based on user experience, technical complexity, and business impact. Recommend a solution that balances these factors, such as refunding inserted bills with clear communication, and outline how to implement it robustly.

Pro tip: Emphasize that the best solution often involves preventing the issue altogether by dynamically managing change inventory and integrating with payment systems for cashless alternatives. This shows forward-thinking and system-level design maturity.

1. Clarify Requirements and Constraints

Ask questions to understand the vending machine's capabilities, typical user scenarios, and business rules. For example, does it accept only bills, or also coins/cards? What is the expected user demographic?

2. Evaluate Options

Compare rejecting the purchase outright versus refunding inserted bills. Consider factors like user frustration, potential for lost sales, technical feasibility of refunding, and compliance with financial regulations.

3. Consider Edge Cases and Failure Modes

Think about scenarios such as partial refunds, bill jams, or power failures during refund. How would the system recover? Ensure the chosen approach handles these gracefully.

4. Propose a Solution with Justification

Recommend a primary approach (e.g., refund inserted bills) and explain why it's better for user experience and business. Mention fallback mechanisms like offering cashless payment or exact change only.

5. Outline Implementation and Monitoring

Describe how to implement the solution, including hardware/software changes, and how to monitor change inventory to prevent future occurrences. Suggest logging and alerts for low change.

Key Points to Mention

  • User experience: refunding is less frustrating than rejection, but must be seamless.
  • Technical complexity: refunding requires reliable bill dispensing and error handling.
  • Business impact: lost sales vs. cost of maintaining change inventory.
  • Regulatory compliance: refunding may be required by law in some jurisdictions.
  • Preventive measures: dynamic pricing, cashless payments, or change inventory monitoring.
  • Edge cases: handling partial refunds, jams, and power failures.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.