-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoldman_bestaverage.java
More file actions
executable file
·103 lines (95 loc) · 3.25 KB
/
goldman_bestaverage.java
File metadata and controls
executable file
·103 lines (95 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Neel_Kapadia
*/
import java.util.*;
public class goldman_bestaverage {
static int bestAverageGrade(String[][] scores) {
HashMap<String,Integer> grade = new HashMap<String,Integer>();
HashMap<String,Integer> count = new HashMap<String,Integer>();
for(int i=0;i<scores.length;i++){
if(grade.get(scores[i][0])==null){
grade.put(scores[i][0],Integer.parseInt(scores[i][1]));
count.put(scores[i][0],1);
}
else{
int x = grade.get(scores[i][0]);
x = x + Integer.parseInt(scores[i][1]);
grade.put(scores[i][0],x);
x = count.get(scores[i][0]);
x++;
count.put(scores[i][0],x);
}
}
int average = 0;
for(int i = 0;i<scores.length;i++){
if(grade.get(scores[i][0])!=null){
int sum = grade.get(scores[i][0]);
int num = count.get(scores[i][0]);
if(average < (sum/num))
average = sum/num;
}
}
return average;
}
public static void main(String[] args) {
String[][] sc = {{"Bobby","87"},{}};
}
}
/*
static int bestAverageGrade(String[][] scores) {
if(scores.length==0)
return 0;
HashMap<String,Integer> grade = new HashMap<String,Integer>();
HashMap<String,Integer> count = new HashMap<String,Integer>();
for(int i=0;i<scores.length;i++){
if(grade.get(scores[i][0])==null){
grade.put(scores[i][0],Integer.parseInt(scores[i][1]));
count.put(scores[i][0],1);
}
else{
int x = grade.get(scores[i][0]);
x = x + Integer.parseInt(scores[i][1]);
grade.put(scores[i][0],x);
x = count.get(scores[i][0]);
x++;
count.put(scores[i][0],x);
}
}
int average = 0;
for(int i = 0;i<scores.length;i++){
if(grade.get(scores[i][0])!=null){
int sum = grade.get(scores[i][0]);
int num = count.get(scores[i][0]);
if(average < (sum/num))
average = sum/num;
}
}
return average;
}
*/
/*
static String[] uniqueSubstrings(String inputString, int substringLength) {
if(inputString.length() == 0)
return null;
ArrayList<String> arr = new ArrayList<String>();
String temp;
for(int i = 0;i<=inputString.length()-substringLength;i++){
temp = inputString.substring(i, i+substringLength);
if(!arr.contains(temp))
arr.add(temp);
}
String [] output = new String[arr.size()];
int i = 0;
arr.sort(String::compareToIgnoreCase);
for(String s : arr){
output[i++] = s;
}
return output;
}
*/