HackerRank Chocolate Feast problem solution YASH PAL, 31 July 20241 December 2025 In this HackerRank Chocolate Feast problem solution, you need to complete the chocolateFeast function that has three integer variables as a parameter and need to return the number of chocolate bobby can eat after taking full advantage of the promotion.Little Bobby loves chocolate. He frequently goes to his favorite 5 & 10 store, Penny Auntie, to buy them. They are having a promotion at Penny Auntie. If Bobby saves enough wrappers, he can turn them in for a free chocolate.Examplen = 15c = 3m = 2He has 15 to spend, bars cost 3, and he can turn in 2 wrappers to receive another bar. Initially, he buys 5 bars and has 5 wrappers after eating them. He turns in 4 of them, leaving him with 1, for 2 more bars. After eating those two, he has 3 wrappers, turns in 2 leaving him with 1 wrapper and his new bar. Once he eats that one, he has 2 wrappers and turns them in for another bar. After eating that one, he only has wrapper, and his feast ends. Overall, he has eaten 5+2+1+1=9 bars.Hackerrank Chocolate Feast problem solution in Python programming.def chocolates(N, C, M): total = int(N/C); empty_wrapper = total while empty_wrapper >= M: temp = int(empty_wrapper/M); total = total + temp; empty_wrapper = empty_wrapper - (temp*M) + temp; return total; T = int(input()) result = []; for i in range(T): (N, C, M) = map(int, input().split()); result = result + [chocolates(N,C,M)]; print('n'.join(map(str, result)))Chocolate Feast problem solution in Java programming.import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); scanner.nextLine(); while (scanner.hasNext()) { int money = scanner.nextInt(); int price = scanner.nextInt(); int bonus = scanner.nextInt(); int count = money / price; int wrappers = count; while (wrappers >= bonus) { int freebies = wrappers / bonus; count += freebies; wrappers = freebies + wrappers % bonus; } System.out.println(count); } } }Problem solution in C++ programming.#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ ios_base::sync_with_stdio(0); int T, N, C, M, w, res; cin >> T; while (T--) { cin >> N >> C >> M; w = res = N/C; while (w >= M) { res += w/M; w = (w%M) + w/M; } cout << res << "n"; } return 0; }Problem solution in C programming.#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int testcases=0; int N=0,M=0,C=0; int i=0, now=0; scanf("%d",&testcases); int temp = 0; int answer[testcases]; for(i=0;i<testcases;i++) { scanf("%d",&N); scanf("%d",&C); scanf("%d",&M); temp = N/C; now=temp; answer[i]=temp; while (now>=M) { answer[i] = answer[i] + (now/M); now=now - (now/M)*M + now/M; } //printf("first = %d Second = %dn",N/C,((N/C)/M)); } for(i=0;i<testcases;i++) printf("%dn",answer[i]); return 0; }Problem solution in JavaScript programming.function parseInts(line) { return line.split(' ').map(function(x) { return parseInt(x, 10) }); } function solve(n, c, m) { var chocolates = Math.floor(n / c); return chocolates + Math.floor((chocolates - 1) / (m - 1)); } function processData(input) { var lines = input.split('n'); for (var t = parseInts(lines.shift())[0]; t > 0; t -= 1) { var ints = parseInts(lines.shift()); console.log(solve.apply(null, ints)); } } process.stdin.resume(); process.stdin.setEncoding("ascii"); _input = ""; process.stdin.on("data", function (input) { _input += input; }); process.stdin.on("end", function () { processData(_input); }); Algorithms coding problems solutions AlgorithmsHackerRank