PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates algorithmic optimization and combinatorial reasoning in the coin-change domain, measuring proficiency with efficient numeric manipulation, counting strategies, and handling of fixed coin denominations.

  • hard
  • Snowflake
  • Coding & Algorithms
  • Software Engineer

Minimize coins with overpay and change

Company: Snowflake

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

You have an unlimited number of coins with denominations: - `1, 5, 10, 50, 100, 200` You need to pay exactly `n` units to another person. You are allowed to **overpay**, and the other person will always be able to give you **exact change** (they also have unlimited coins). Define the **total coins used** as: - the number of coins you give to pay, **plus** - the number of coins you receive back as change. Return the **minimum possible total number of coins** needed to complete the transaction. ### Input - A single integer `n`. ### Output - A single integer: the minimum total number of coins exchanged. ### Example **Input:** ``` 41 ``` **Output:** ``` 3 ``` **Explanation:** Pay `50 + 1` (2 coins) and receive `10` as change (1 coin), total `2 + 1 = 3`. ### Constraints - Assume `0 ≤ n ≤ 10^9`. - Both payer and receiver have unlimited coins of each denomination.

Quick Answer: This question evaluates algorithmic optimization and combinatorial reasoning in the coin-change domain, measuring proficiency with efficient numeric manipulation, counting strategies, and handling of fixed coin denominations.

You have an unlimited number of coins with denominations 1, 5, 10, 50, 100, and 200. You need to pay exactly n units to another person. You are allowed to overpay, and the other person can always give you exact change using the same coin denominations. The total number of coins used is: - the number of coins you give, plus - the number of coins you receive back as change. Return the minimum possible total number of coins exchanged.

Constraints

  • 0 <= n <= 10^9
  • Both payer and receiver have unlimited coins of denominations 1, 5, 10, 50, 100, 200

Examples

Input: (0,)

Expected Output: 0

Explanation: No payment is needed, so no coins are exchanged.

Input: (41,)

Expected Output: 3

Explanation: Pay 51 using coins 50 + 1 (2 coins) and receive 10 as change (1 coin), for a total of 3.

Input: (49,)

Expected Output: 2

Explanation: Pay 50 with one coin and receive 1 as change with one coin, total 2.

Input: (159,)

Expected Output: 4

Explanation: Pay 160 using 100 + 50 + 10 (3 coins) and receive 1 as change (1 coin), total 4.

Input: (199,)

Expected Output: 2

Explanation: Pay 200 with one coin and receive 1 as change with one coin, total 2.

Input: (201,)

Expected Output: 2

Explanation: Exact payment is best here: pay 200 + 1 using 2 coins.

Input: (999999999,)

Expected Output: 5000001

Explanation: Pay 1,000,000,000 using 5,000,000 coins of value 200, then receive 1 as change. Total = 5,000,001 coins.

Hints

  1. If you overpay by d, then the total cost becomes: coins needed to make n + d, plus coins needed to make d as change.
  2. Write n = 200 * q + r. Overpaying by an extra full 200 always adds at least 2 more coins overall, so you only need to try overpay amounts from 0 to 199.
Last updated: Apr 29, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Implement a JSON Parser - Snowflake (hard)
  • Solve Matrix and Array Distance Problems - Snowflake (medium)
  • Solve Array Distance and Wiki Navigation - Snowflake (medium)
  • Implement Document Predicate APIs - Snowflake (medium)
  • Find Shortest Wiki Click Path - Snowflake (medium)