ATM Notes Breakdown
JavaScript
Medium
5 views
Problem Description
Given amount, break it into notes of 2000,500,200,100,50,20,10 using greedy. Print counts in same order. If amount is not multiple of 10 or negative, print -1.
Input Format
One integer amount.
Output Format
7 integers counts or -1.
Official Solution
const fs=require('fs');const s=fs.readFileSync(0,'utf8').trim();if(!s)process.exit(0);let amt=BigInt(s);if(amt<0n||amt%10n!==0n){process.stdout.write('-1');process.exit(0);}const den=[2000n,500n,200n,100n,50n,20n,10n];let out=[];for(const d of den){const c=amt/d;out.push(c.toString());amt-=c*d;}process.stdout.write(out.join(' '));
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!