This guide walks through how to build out the common Ruby coding interview question: how to build out an ATM dispensing method.


Implement an ATM method that properly dispenses the correct denominations to a user.

Exercise File

Code File

Exercise Description

Build out a method that takes two arguments: the total amount of money requested and the denominations that can be returned. And return the count of how many bills of each denomination should be returned to a user.

Example Data Input

245, [20, 10, 5]

In this example, 245 is the total amount requested at the ATM, and the array represents 20, 10, and 5 dollar bills.

Expected Output

{20=>12, 10=>0, 5=>1}

This hash represents 12 $20 dollar bills and 1 $5 dollar bills.

Real World Usage

This exercise is a very popular Ruby coding interview question. This will test your knowledge of several mathematical methods along with how you can combine multiple functional programming concepts.


Can be found on the solutions branch on github.


  1. One question I have is, can we just say

    hash[denomination] = total.divmod(denomination).first

    return raw_data , so that we can probably avoid this portion. do |k, v|
    raw_data[k] = v.first


Please enter your comment!
Please enter your name here