Interview Question


Country: United States




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

It has enough hint - and you can easily convert it to Python.

def avg_mark_lowest_id_student( data_file ){
  students = dict() //  dict 
  lowest_student_id = num("inf")
  for ( line : file(data_file) ){
    #(id, sub, marks) = line.split("\\W+")
    id = int(id) // cast to int
    if ( id !@ students ){
      if ( id < lowest_student_id ){
        lowest_student_id = id // update the lowest id
      }
      students[id] = list()
    }
    students[id] += marks
  }
  data_list = students[lowest_student_id]
  tot = sum( data_list )
  avg = float(tot)/size(data_list)
}

- NoOne May 28, 2021 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def get_average_marks():
  with open('my_file.txt', 'r') as f:
    file_content = f.read()
  lines = file_content.split('\n')
  students = {}
  lowest_id = 0
  for line in lines:
    row = line.split(",")
    row = [x.strip() for x in row]
    id = int(row[0])
    if lowest_id == 0 or id < lowest_id:
      lowest_id = id
    marks = int(row[2])
    if id not in students:
      students[id] = { "marks": 0, "count": 0 }
    students[id]['marks'] += marks
    students[id]['count'] += 1

  return str(round(students[lowest_id]['marks'] / students[lowest_id]['count']))

print(get_average_marks())

- Anonymous June 11, 2021 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def get_average_marks():
  with open('my_file.txt', 'r') as f:
    file_content = f.read()
  lines = file_content.split('\n')
  students = {}
  lowest_id = 0
  for line in lines:
    row = line.split(",")
    row = [x.strip() for x in row]
    id = int(row[0])
    if lowest_id == 0 or id < lowest_id:
      lowest_id = id
    marks = int(row[2])
    if id not in students:
      students[id] = { "marks": 0, "count": 0 }
    students[id]['marks'] += marks
    students[id]['count'] += 1

  return str(round(students[lowest_id]['marks'] / students[lowest_id]['count']))

print(get_average_marks())

- Chris Willett June 11, 2021 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def get_average_marks():
  with open('my_file.txt', 'r') as f:
    file_content = f.read()
  lines = file_content.split('\n')
  students = {}
  lowest_id = 0
  for line in lines:
    row = line.split(",")
    row = [x.strip() for x in row]
    id = int(row[0])
    if lowest_id == 0 or id < lowest_id:
      lowest_id = id
    marks = int(row[2])
    if id not in students:
      students[id] = { "marks": 0, "count": 0 }
    students[id]['marks'] += marks
    students[id]['count'] += 1

  return str(round(students[lowest_id]['marks'] / students[lowest_id]['count']))

print(get_average_marks())

- chriswillett77 June 11, 2021 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Moderator, please delete my first two posts. They did not show up when I posted and refreshed. It wasn't until I created an account that all 3 of my attempts showed up.
Thanks!

- chriswillett77 June 11, 2021 | 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