La Liga CodeChef Solution

Problem – La Liga CodeChef Solution

Today is the final round of La Liga, the most popular professional football league in the world. Real Madrid is playing against Malaga and Barcelona is playing against Eibar. These two matches will decide who wins the league title. Real Madrid is already 3 points ahead of Barcelona in the league standings. In fact, Real Madrid will win the league title, except for one scenario: If Real Madrid loses against Malaga, and Barcelona wins against Eibar, then the La Liga title will go to Barcelona. In any other combination of results, Real Madrid will win the title.

You will be given multiple scenarios for these two games, where in each one you will be given the number of goals each team scored in their respective match. A team wins a match if it scores more than the opponent. In case they score the same number of goals, it’s a draw. Otherwise, the team loses the game. You are asked to tell the winner of the La Liga title in each scenario.


The first line contains a single number T, the number of scenarios. Each scenario is described by four lines. Each line starts with a team name followed by the number of goals this team scored in its corresponding match. (Barcelona plays Eibar and Real Madrid plays Malaga). The names are given in any arbitrary order within a scenario.


For each scenario, output a single line showing the title winner in case this scenario happens. It should be either “RealMadrid” or “Barcelona”.


  • 1 ≤ T ≤ 500
  • 0 ≤ number of goals scored by a team in a match ≤ 20

Sample 1:

Barcelona 2
Malaga 1
RealMadrid 1
Eibar 0
Malaga 3
RealMadrid 2
Barcelona 8
Eibar 6

La Liga 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 in = new Scanner(;
        int t = in.nextInt();

        while (t-- > 0) {
            HashMap<String, Integer> map = new HashMap<>();
            for (int i = 0; i < 4; i++) {
                map.put(, in.nextInt());

            if (map.get("RealMadrid") < map.get("Malaga") && map.get("Barcelona") > map.get("Eibar")) {
            }else {


La Liga CodeChef Solution in Pyth 3

t = int(input())
for i in range(0,t):
    d = dict()
    for _ in range(0,4):
        name,goals = input().split()
        d[name] = goals
    if d["RealMadrid"]<d["Malaga"] and d["Barcelona"]>d["Eibar"]: print("Barcelona")
    else: print("RealMadrid")

La Liga CodeChef Solution in C++14

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t; cin>>t;
	  int b,m,r,e;string s;
	  for(int i=0;i<4;i++){
	      else if(s[0]=='M')cin>>m;
	      else if(s[0]=='R')cin>>r;
	      else cin>>e;
	  if(r<m && b>e)
	return 0;
La Liga CodeChef Solution Review:

In our experience, we suggest you solve this La Liga CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the La Liga CodeChef Solution

Find on CodeChef


I hope this La Liga CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions

Leave a Reply

Your email address will not be published. Required fields are marked *