Find goal difference for maximum wins and recent team with that goal difference

  

import java.io.*;

import java.util.*;

  

class GFG {

  

    

    

    

    public static void solve(String HT[], int HG[],

                             String AT[], int AG[])

    {

        int N = 4;

  

        

        Map<Integer, Integer> gd_freq

            = new HashMap<Integer, Integer>();

  

        

        

        

        Map<Integer, String> gd_team

            = new HashMap<Integer, String>();

  

        

        for (int i = 0; i < N; i++) {

            int gd = HG[i] - AG[i];

            if (gd >= 0) {

                int prev_freq = 0;

                if (gd_freq.get(gd) != null) {

                    prev_freq = gd_freq.get(gd);

                }

                gd_freq.put(gd, prev_freq + 1);

                gd_team.put(gd, HT[i]);

            }

        }

  

        

        int max_index = 0;

  

        

        int max_freq = -1;

        for (Map.Entry<Integer, Integer> entry :

             gd_freq.entrySet()) {

  

            

            

            if (max_freq <= entry.getValue()) {

                max_freq = entry.getValue();

                max_index = entry.getKey();

            }

        }

  

        

        if (max_freq == -1) {

            System.out.println("-1");

        }

        else {

            System.out.println(max_index + " "

                               + gd_team.get(max_index));

        }

    }

  

    

    public static void main(String[] args)

    {

        int N = 4;

  

        

        String HT[]

            = { "mumbai", "bengaluru", "goa", "bengal" };

  

        

        int HG[] = { 3, 1, 4, 3 };

  

        

        String AT[]

            = { "goa", "kerala", "hyderabad", "goa" };

  

        

        int AG[] = { 2, 0, 5, 1 };

  

        

        solve(HT, HG, AT, AG);

    }

}