A file contains data as follows : {Student name, marks in 3 subjects}.
There are N students in a class. Find the student who has maximum average score.
Note: The average score is always floored.
 
Example 1:
Input:
N = 2
S = {"Shrikanth 20 30 10", "Ram 100 50 10"}
Output:
Ram 53
Explantion:
Shrikanth has an average of 20, whereas
Ram has a average of 53. So, Ram has the
maximum average.
Example 2:
Input:
N = 3
S = {"Adam 50 10 40", "Rocky 100 90 10", "Suresh 10 90 100"}
Output:
Rocky Suresh 66
Explantion:
Rocky and Suresh both have an average of 66, which is the
highest in the class.
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function studentRecord() which takes an Integer N and a vector of vector of strings where each string vector contains 4 space separated inputs, the first being the name of the student and the rest being the marks of the student. The function should return a string consisting of two or more words where the last word is the max average of the class and the preceding words are names of student/s who have the max average. The names of the students should appear in the same order as they are given in the Input.
 
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
 
Constraints:
1 <= N <= 10^{4}
1 <= marks <= 100
1 <= Length of the Name <= 10

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3

class Solution:
    def studentRecord(self, l, N): 
        # code here 

Solutions:
class Solution:

	def studentRecord(self, l, N):
		st = ''
		an = 0
		for i in l:
			avg = 0
			for j in range(1, 4):
				avg += int(i[j])
			avg = avg // 3
			if avg == an:
				st = st + ' ' + i[0]
			if avg > an:
				st = i[0]
				an = avg
		return st + ' ' + str(an)


class Solution:

	def studentRecord(self, l, N):
		names = [l[0][0]]
		cmav = sum(map(int, l[0][1:])) // 3
		for x in l[1:]:
			(dn, *dm) = x
			avg = sum(map(int, x[1:])) // 3
			if avg == cmav:
				names.append(dn)
			elif avg > cmav:
				names.clear()
				names.append(dn)
				cmav = avg
		return ' '.join([*names, str(cmav)])


class Solution:

	def studentRecord(self, l, N):
		st = ''
		cnt = 0
		for z in l:
			c = (int(z[1]) + int(z[2]) + int(z[3])) // 3
			if c > cnt:
				st = z[0]
				cnt = c
			elif c == cnt:
				st = st + ' ' + z[0]
		return st + ' ' + str(cnt)


class Solution:

	def studentRecord(self, l, N):
		avg = []
		ind = []
		summ = 0
		s = ''
		for i in l:
			for j in i:
				if j.isdigit() == True:
					summ = summ + int(j)
			avg.append(summ // 3)
			summ = 0
		b = max(avg)
		t = 0
		while t < len(avg):
			if avg[t] == b:
				ind.append(t)
			t += 1
		for k in ind:
			s = s + l[k][0] + ' '
		s = s + str(b)
		return s


class Solution:

	def studentRecord(self, l, N):
		(m, res) = (0, '')
		for i in l:
			(t, s) = (list(i), 0)
			for i in range(1, 4):
				s += int(t[i])
			avg = s // 3
			if avg > m:
				m = avg
				res = t[0] + ' '
			elif avg == m:
				res += t[0] + ' '
		res += str(m)
		return res


class Solution:

	def studentRecord(self, l, N):
		mark = 0
		name = []
		for i in l:
			c = (int(i[1]) + int(i[2]) + int(i[3])) // 3
			if c > mark:
				name = [i[0]]
				mark = c
			elif c == mark:
				name.append(i[0])
		s = ''
		for i in name:
			s += i
			s += ' '
		m = str(mark)
		return s + m


import re

class Solution:

	def studentRecord(self, l, N):
		max = 0
		name_str = ''
		for i in range(N):
			regex = '\\d+'
			nums = re.findall('\\d+', str(l[i]))
			name = re.findall('\\w+', str(l[i]))
			num_sum = sum(list(map(int, nums)))
			avg = int(num_sum / 3)
			if avg > max:
				max = avg
				name_str = name[0] + ' '
			elif avg == max:
				name_str += ''.join(name[0]) + ' '
		name_str += ''.join(str(max))
		return name_str


class Solution:

	def studentRecord(self, l, N):
		maxa = -1
		names = []
		for record in l:
			marks = list(map(int, record[1:]))
			temp = sum(marks) // 3
			if temp > maxa:
				maxa = temp
				names = [record[0]]
			elif temp == maxa:
				names.append(record[0])
		result = names + [str(maxa)]
		return ' '.join(result)


import math

class Solution:

	def studentRecord(self, l, N):
		d = dict()
		for i in l:
			temp = i
			name = temp[0]
			avg = math.floor((int(temp[1]) + int(temp[2]) + int(temp[3])) / 3)
			if avg not in d:
				d[avg] = [name]
			else:
				d[avg].append(name)
		max_avg = max(d)
		names = d[max_avg]
		names.append(str(max_avg))
		return ' '.join(names)


import math

class Solution:

	def studentRecord(self, l, N):
		maximumName = []
		maximumAverage = 0
		for itr in range(N):
			k = math.floor((int(l[itr][1]) + int(l[itr][2]) + int(l[itr][3])) // 3)
			if maximumAverage < k:
				maximumAverage = k
		for itr in range(N):
			k = math.floor((int(l[itr][1]) + int(l[itr][2]) + int(l[itr][3])) // 3)
			if maximumAverage == k:
				maximumName.append(l[itr][0])
		return ' '.join(maximumName) + ' ' + str(maximumAverage)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		l = []
		for i in range(N):
			s = list(map(str, input().split()))
			l.append(s)
		ob = Solution()
		print(ob.studentRecord(l, N))


class Solution:

	def studentRecord(self, l, N):
		h = []
		d = 0
		for i in l:
			e = int(i[1]) + int(i[2]) + int(i[3])
			e = e // 3
			h.append([i[0], e])
			if e > d:
				d = e
		t = ''
		for i in h:
			if i[1] == d:
				t += i[0] + ' '
		t += str(d)
		return t
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		l = []
		for i in range(N):
			s = list(map(str, input().split()))
			l.append(s)
		ob = Solution()
		print(ob.studentRecord(l, N))


import math

class Solution:

	def studentRecord(self, l, N):
		name = ''
		marks = -math.inf
		for i in l:
			n = i[0]
			sm = 0
			for k in range(1, 4):
				sm += int(i[k])
			sm = math.floor(sm / 3)
			if marks < sm:
				name = n
				marks = sm
			elif marks == sm:
				name += ' ' + n
		return name + ' ' + str(int(marks))
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		l = []
		for i in range(N):
			s = list(map(str, input().split()))
			l.append(s)
		ob = Solution()
		print(ob.studentRecord(l, N))


import math

class Solution:

	def studentRecord(self, l, N):
		maxAvgScoreStudents = ''
		if l is None or len(l) == 0:
			return maxAvgScoreStudents
		maxAvgScore = -math.inf
		avgScore = -math.inf
		for rArr in l:
			if rArr is None:
				break
			try:
				avgScore = (float(rArr[1]) + float(rArr[2]) + float(rArr[3])) // 3
			except:
				return 'Invalid student score in the file'
			if avgScore > maxAvgScore:
				maxAvgScore = avgScore
				maxAvgScoreStudents = rArr[0]
			elif avgScore == maxAvgScore:
				maxAvgScoreStudents += ' ' + rArr[0]
		maxAvgScoreStudents += ' ' + str(int(maxAvgScore))
		return maxAvgScoreStudents


class Solution:

	def studentRecord(self, l, N):
		max_avg = 0
		final_name = ''
		name = ''
		m_list = []
		avg = 0
		for i in range(N):
			name = l[i][0]
			avg = (int(l[i][1]) + int(l[i][2]) + int(l[i][3])) // 3
			if avg > max_avg:
				name = name
				final_name = name
				max_avg = avg
			elif avg == max_avg:
				final_name = final_name + ' ' + name
		return final_name + ' ' + str(max_avg)


class Solution:

	def studentRecord(self, l, N):
		ans = ''
		max_average = -1
		for s in l:
			name = s[0]
			marks = [int(i) for i in s[1:]]
			m = sum(marks) // 3
			if m == max_average:
				ans += ' ' + name
			elif m > max_average:
				max_average = m
				ans = name
		ans += ' ' + str(max_average)
		return ans


class Solution:

	def studentRecord(self, a, n):
		max = 0
		res = ''
		for i in a:
			avg = int((float(i[1]) + float(i[2]) + float(i[3])) / 3)
			if max < avg:
				max = avg
				res = i[0]
			elif max == avg:
				res = res + ' ' + i[0]
		return res + ' ' + str(int(max))


class Solution:

	def studentRecord(self, l, N):
		avglist = []
		maxavg = 0
		for eachlist in l:
			newavg = sum([int(i) for i in eachlist[1:]]) // 3
			if newavg > maxavg:
				maxavg = newavg
			avglist.append(newavg)
		S = ''
		for ind in range(N):
			if avglist[ind] == maxavg:
				S += l[ind][0] + ' '
		return S + str(maxavg)


class Solution:

	def studentRecord(self, l, N):
		highestAvg = -999
		highestName = ''
		for i in range(N):
			avg = sum([int(l[i][j]) for j in range(1, 4)]) // 3
			if avg >= highestAvg:
				if avg == highestAvg:
					highestName += ' ' + l[i][0]
				else:
					highestName = l[i][0]
				highestAvg = avg
		return highestName + ' ' + str(highestAvg)


class Solution:

	def studentRecord(self, l, N):
		Max_val = 0
		Max_ans = None
		dict1 = {}
		li = []
		for i in l:
			value = int(sum((int(i[x]) for x in range(1, len(i)))) / (len(i) - 1))
			if value > Max_val:
				Max_val = value
				li = []
				li.append(i[0])
			elif value == Max_val:
				li.append(i[0])
		Max_ans = ' '.join(li)
		return Max_ans + ' ' + str(Max_val)


class Solution:

	def studentRecord(self, l, N):
		s = ''
		msum = 0
		for i in l:
			res = i
			ans = (int(res[1]) + int(res[2]) + int(res[3])) // 3
			if ans > msum:
				s = ''
				s += res[0]
				msum = ans
			elif ans == msum:
				s += ' '
				s += res[0]
		s += ' '
		s += str(msum)
		return s


class Solution:

	def studentRecord(self, l, N):
		(studentWithMaxAvgScore, maxAvgScore) = ('', 0)
		for idx in range(N):
			currStudentName = l[idx][0]
			currStudentAvgScore = (int(l[idx][1]) + int(l[idx][2]) + int(l[idx][3])) // 3
			if idx == 0:
				studentWithMaxAvgScore = currStudentName
				maxAvgScore = currStudentAvgScore
			elif currStudentAvgScore > maxAvgScore:
				studentWithMaxAvgScore = currStudentName
				maxAvgScore = currStudentAvgScore
			elif currStudentAvgScore == maxAvgScore:
				studentWithMaxAvgScore += ' ' + currStudentName
		return studentWithMaxAvgScore + ' ' + str(maxAvgScore)


class Solution:

	def studentRecord(self, l, N):
		studentWithMaxAvgScore = l[0][0]
		maxAvgScore = (int(l[0][1]) + int(l[0][2]) + int(l[0][3])) // 3
		for idx in range(1, N):
			studentName = l[idx][0]
			avgScore = (int(l[idx][1]) + int(l[idx][2]) + int(l[idx][3])) // 3
			if avgScore > maxAvgScore:
				studentWithMaxAvgScore = studentName
				maxAvgScore = avgScore
			elif avgScore == maxAvgScore:
				studentWithMaxAvgScore += ' ' + studentName
		return studentWithMaxAvgScore + ' ' + str(maxAvgScore)


class Solution:

	def studentRecord(self, l, N):
		student = ''
		maximum = 0
		for vector in l:
			av_grade = 0
			for i in range(1, 3 + 1):
				av_grade += int(vector[i])
			av_grade = int(av_grade / 3)
			if av_grade == maximum:
				student += ' ' + vector[0]
			elif av_grade > maximum:
				maximum = int(av_grade)
				student = vector[0]
		return student + ' ' + str(maximum)


class Solution:

	def studentRecord(self, l, N):
		ans = ''
		avg = []
		for i in l:
			avg.append((int(i[1]) + int(i[2]) + int(i[3])) // 3)
		x = max(avg)
		for i in range(len(avg)):
			if avg[i] == x:
				ans = ans + l[i][0] + ' '
		return ans + '' + str(x)