Give Correct Change to Customers in Order

Quick Overview

Give Correct Change to Customers in Order. Each drink costs $5. Starting with no cash, serve the queue in bills order.

Give Correct Change to Customers in Order

Company: Infosys

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Each drink costs `$5`. Starting with no cash, serve the queue in bills order. Each customer buys one drink and pays with a `$5`, `$10` or `$20` bill. Return whether you can give exact change to every customer immediately. ```cpp class Solution { public: bool lemonadeChange(vector<int>& bills); }; ``` ### Examples **Example 1:** ```text bills = [5,10,5,20] Output: true Explanation: The10 payment uses one5 in change; later the20 payment uses one10 and one5. ``` **Example 2:** ```text bills = [10] Output: false Explanation: There is no initial5 bill to give as change. ``` ### Constraints - Customer count lies in [1,100000]. - Each payment is exactly 5,10 or 20. ### Contract considerations Preserve empty initial cash and exact immediate change. ```hint Read the boundary condition Which change choice preserves the more flexible smaller bills? ``` ### Boundary reminders Preserve empty initial cash and exact immediate change.

Overview: Give Correct Change to Customers in Order. Each drink costs $5. Starting with no cash, serve the queue in bills order.

Infosys logo
Infosys
Sep 3, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Each drink costs $5. Starting with no cash, serve the queue in bills order. Each customer buys one drink and pays with a $5, $10 or $20 bill. Return whether you can give exact change to every customer immediately.

class Solution {
public:
    bool lemonadeChange(vector<int>& bills);
};

Examples

Example 1:

bills = [5,10,5,20]
Output: true
Explanation: The10 payment uses one5 in change; later the20 payment uses one10 and one5.

Example 2:

bills = [10]
Output: false
Explanation: There is no initial5 bill to give as change.

Constraints

  • Customer count lies in [1,100000].
  • Each payment is exactly 5,10 or 20.

Contract considerations

Preserve empty initial cash and exact immediate change.

Boundary reminders

Preserve empty initial cash and exact immediate change.