MAGMA Interview Question for abcs


Team: IOT
Country: United States




Comment hidden because of low score. Click to expand.
0
of 0 vote

import re

# Input/output files
readFile = open('input','r')
out = open('output.txt','w')

# Remove unnecessary spaces and split each line
val = re.sub(','+' ',',',readFile.read().strip())
val_list = val.split('\n')

# create a set -> [Student ID, Subject, Marks]
stu_arr = {}
for i in range(len(val_list)):
    stu_arr[i] = val_list[i].split(',')

# Create a key, value pair for each student where key = Student ID
# and value = sum of all subjects
stu_kv = {}
for i in range(len(stu_arr)):
    if not stu_arr[i][0] in stu_kv:
        stu_kv[stu_arr[i][0]] = int(stu_arr[i][2])
    else:
        stu_kv[stu_arr[i][0]] = int(stu_kv[stu_arr[i][0]]) + int(stu_arr[i][2])

# Get the number of students who has total marks >= 100
counter = 0
for k,v in stu_kv.items():
    if v >= 100:
        counter += 1

# Write into output file
out.write(str(counter))

- Bhadresh Dhanani September 28, 2016 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More