I got a question today and tried but doesn't found an relevent solution. The question is:
Suppose we have a 2D array containing the name of city and total number of products. The name of city could repeat in the list.
Now what we have to do is
- Count the number of product sold in one city and save them in another 2d array having unique city name and total number of products sold.
- Print the second city having highest products sold.
A sample list could be for consideration is:
private static String[][] arr = new String[][]{
{"New Delhi", "5000"},
{"Chennai", "4300"},
{"Goa", "2940"},
{"New Delhi", "2003"},
{"Kolkata", "8904"},
{"Kerala", "8972"},
{"New Delhi", "8922"},
{"Chennai", "8217"},
{"New Delhi", "2462"},
{"Kolkata", "5564"},
{"Kerala", "9934"},
{"New Delhi", "100"},
{"Kolkata", "892"},
{"Kerala", "9406"},
{"New Delhi", "2003"},
{"Chennai", "1049"}
};
Note: I already tried this question with Map Interface. Only looking for solution with Multidimensional Array