Exchanging Coin : wrong answer error

problem
my code

which test case is this code wrong for
because it works for 12,32 (sample test cases)

You need to call for n/2,n/3,n/4 without checking the perfect divison.
And second thing do not use array for these kind of problems where all positions are not used in array.
Instead,use hash map.
I am sharing my implementation.Hope it solves your query.
https://ide.codingblocks.com/#/s/14444

1 Like

Thanks…some more queries:
what if 0 was also one the possible answers ,how would the map be initialized then?
and is map.clear() necessary?