Laddu CodeChef Solution

Today we will be solving Laddu CodeChef Solution which is a part of CodeChef DSA Learning Series.

As you already know that this site does not contain only the Codefchef solutions here, you can also find the solution for other programming problems. I.e. LeetcodeC programsC++ Programs SolutionsPython ProgramsWeb Technology, Data StructuresRDBMS Programs and Java Programs Solutions.

Laddu CodeChef Solution
Laddu CodeChef Solution


Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.

You might have heard about our new goodie distribution program aka the “Laddu Accrual System“. This problem is designed to give you a glimpse of its rules. You can read the page once before attempting the problem if you wish, nonetheless we will be providing all the information needed here itself.

Laddu Accrual System is our new goodie distribution program. In this program, we will be distributing Laddus in place of goodies for your winnings and various other activities (described below), that you perform on our system. Once you collect enough number of Laddus, you can then redeem them to get yourself anything from a wide range of CodeChef goodies.

Let us know about various activities and amount of laddus you get corresponding to them.

  • Contest Win (CodeChef’s Long, Cook-Off, LTIME, or any contest hosted with us) : 300 + Bonus (Bonus = 20 – contest rank). Note that if your rank is > 20, then you won’t get any bonus.
  • Top Contributor on Discuss : 300
  • Bug Finder : 50 – 1000 (depending on the bug severity). It may also fetch you a CodeChef internship!
  • Contest Hosting : 50

You can do a checkout for redeeming laddus once a month. The minimum laddus redeemable at Check Out are 200 for Indians and 400 for the rest of the world.

You are given history of various activities of a user. The user has not redeemed any of the its laddus accrued.. Now the user just wants to redeem as less amount of laddus he/she can, so that the laddus can last for as long as possible. Find out for how many maximum number of months he can redeem the laddus.


  • The first line of input contains a single integer T denoting number of test cases
  • For each test case:
    • First line contains an integer followed by a string denoting activities, origin respectively, where activities denotes number of activities of the user, origin denotes whether the user is Indian or the rest of the world. origin can be “INDIAN” or “NON_INDIAN”.
    • For each of the next activities lines, each line contains an activity.
      An activity can be of four types as defined above.
      • Contest Win : Input will be of form of CONTEST_WON rank, where rank denotes the rank of the user.
      • Top Contributor : Input will be of form of TOP_CONTRIBUTOR.
      • Bug Finder : Input will be of form of BUG_FOUND severity, where severity denotes the severity of the bug.
      • Contest Hosting : Input will be of form of CONTEST_HOSTED.


For each test case, find out the maximum number of months for which the user can redeem the laddus accrued.


  • 1 ≤ T, activities ≤ 100
  • 1 ≤ rank ≤ 5000
  • 50 ≤ severity ≤ 1000


There is only a single subtask with 100 points.



LinkedIn Skill Assessment Answers

Coursera Quiz Answers


In the first example,

  • For winning contest with rank 1, user gets 300 + 20 – 1 = 319 laddus.
  • For top contributor, user gets 300 laddus.
  • For finding a bug with severity of 100, user gets 100 laddus.
  • For hosting a contest, user gets 50 laddus.

So, overall user gets 319 + 300 + 100 + 50 = 769 laddus. Now, the user is an Indian user, he can redeem only 200 laddus per month. So, for first three months, he will redeem 200 * 3 = 600 laddus. The remaining 169 laddus, he can not redeem as he requires at least 200 laddues in a month to redeem.

So, answer is 3.

In the second example, user is a non-Indian user, he can redeem 400 laddues per month. So, in the first month, he will redeem 400 laddus. The remaining 369 laddus, he can not redeem as he requires at least 400 laddues in a month to redeem.

So, answer is 1.

Laddu CodeChef Solution in Java

/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
    public static void main (String[] args) throws java.lang.Exception
        Scanner read = new Scanner(;
        int T = read.nextInt();
        while (T > 0) {
            int activities = read.nextInt();
            int laddus = 0;
            String origin =;
            while (activities > 0) {
                String kind =;
                if (kind.equals("CONTEST_WON")) {
                    int rank = read.nextInt();
                    int bouns = Math.max(0, 20 - rank);
                    laddus += 300 + bouns;
                } else if (kind.equals("TOP_CONTRIBUTOR")) {
                    laddus += 300;
                } else if (kind.equals("BUG_FOUND")) {
                    int severity = read.nextInt();
                    laddus += severity;
                } else if (kind.equals("CONTEST_HOSTED")) {
                    laddus += 50;
            System.out.println(laddus / (origin.equals("INDIAN") ? 200 : 400));

Laddu CodeChef Solution in CPP

#include <iostream>
using namespace std;
int main() {
    int t;
        int a;\
        string nat;
        bool ind=false;
        if(nat == "INDIAN") ind = true;
        long long l=0;
        string s;
        int n;
        for(int i=0;i<a;i++){
            if(s== "CONTEST_WON"){
                if(n<20) l+= 20-n;
            else if(s== "TOP_CONTRIBUTOR" ){
            else if(s== "BUG_FOUND" ){
            else if(s== "CONTEST_HOSTED"){
        if(ind) cout<<l/200<<endl;
        else cout<<l/400<<endl;
    return 0;

Laddu CodeChef Solution in Python

Coming soon

Disclaimer: The above Problem (Laddu CodeChef) is generated by CodeChef but the solution is provided by Chase2learn.This tutorial is only for Educational and Learning purpose.

Finally, we are now, in the end, I just want to conclude some important message for you

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.

Please share our posts on social media platforms and also suggest to your friends to Join Our Groups. Don’t forget to subscribe. 

Sharing Is Caring

Leave a Comment