TCS NQT May 20th Afternoon shift
The first question of the Coding section was easy. But the second question really bugged me. It was about a teacher grading students based on band and printing the band no.of students in it.
Solved it in 20 min, but I could not pass that one test, and I literally tried all the other versions of the current code. Even the question did not mention any constraints.
Did anyone else face the same issue, or is it just me??
Wrote the code below, but only 6/7 test cases passed:
ct = {"A" : 0,"B" : 0 ,"C" : 0,"D" : 0,"E" : 0,"F" : 0,"X" : 0}
n = int(input())
marks = list(map(int,input().split()))
for i in marks:
if i < 0 or i > 100:
ct["X"] += 1
elif 90 <= i <= 100:
ct["A"] += 1
elif 80 <= i < 90:
ct["B"] += 1
elif 70 <= i < 80:
ct["C"] += 1
elif 60 <= i < 70:
ct["D"] += 1
elif 0 <= i < 60:
ct["E"] += 1
else:
ct["F"] += 1
if ct["X"] == n:
print("X")
else:
max_val = max(ct.values())
max_keys = [k for k, v in ct.items() if v == max_val]
print(max_keys[0])
Did anyone pass 7/7 testcases