We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
So I checked a unit case which I failed.
Input : 0 2 9 10 13 16 17 17 18 19
Output : 3
This is not even possible taking into account all possibilities as below:
Take 0, Count=1,0+4=4 so FreeToys=(0,2), remaining ways=8...TotalWays=1+8=9
Take 2, Count=2,2+4=6 so FreeToys=(2), remaining ways=8...TotalWays=2+8=10
Take 9, Count=3,9+4=13 so FreeToys=(9,10,13), remaining ways=5...TotalWays=3+5=8
Take 10, Count=4,10+4=14 so FreeToys=(10,13), remaining ways=5...TotalWays=4+5=9
Take 13, Count=5,13+4=17 so FreeToys=(13,16,17,17), remaining ways=2...TotalWays=5+2=7
Take 16, Count=6,16+4=20 so FreeToys=(16,17,17,18,19), remaining ways=0...TotalWays=6+0=6
Take 17, Count=7,17+4=21 so FreeToys=(17,17,18,19), remaining ways=0...TotalWays=7+0=7
Take 17, Count=8,17+4=21 so FreeToys=(17,17,18,19), remaining ways=0...TotalWays=8+0=8
Take 18, Count=9,18+4=22 so FreeToys=(18,19), remaining ways=0...TotalWays=9+0=9
Take 19, Count=10,19+4=23 so FreeToys=(19), remaining ways=0...TotalWays=10+0=10
Final List of Possible ways = [9,10,8,9,7,6,7,8,9,10]
Minimum way = 6
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Priyanka and Toys
You are viewing a single comment's thread. Return to all comments →
So I checked a unit case which I failed. Input : 0 2 9 10 13 16 17 17 18 19 Output : 3
This is not even possible taking into account all possibilities as below:
Take 0, Count=1,0+4=4 so FreeToys=(0,2), remaining ways=8...TotalWays=1+8=9 Take 2, Count=2,2+4=6 so FreeToys=(2), remaining ways=8...TotalWays=2+8=10 Take 9, Count=3,9+4=13 so FreeToys=(9,10,13), remaining ways=5...TotalWays=3+5=8 Take 10, Count=4,10+4=14 so FreeToys=(10,13), remaining ways=5...TotalWays=4+5=9 Take 13, Count=5,13+4=17 so FreeToys=(13,16,17,17), remaining ways=2...TotalWays=5+2=7 Take 16, Count=6,16+4=20 so FreeToys=(16,17,17,18,19), remaining ways=0...TotalWays=6+0=6 Take 17, Count=7,17+4=21 so FreeToys=(17,17,18,19), remaining ways=0...TotalWays=7+0=7 Take 17, Count=8,17+4=21 so FreeToys=(17,17,18,19), remaining ways=0...TotalWays=8+0=8 Take 18, Count=9,18+4=22 so FreeToys=(18,19), remaining ways=0...TotalWays=9+0=9 Take 19, Count=10,19+4=23 so FreeToys=(19), remaining ways=0...TotalWays=10+0=10
Final List of Possible ways = [9,10,8,9,7,6,7,8,9,10] Minimum way = 6