Meta Interview Question
Technical Phone Screen Coding question: You will be supplied with two data files in CSV format .
The first file contains statistics about various dinosaurs. The second file contains additional data.
Given the following formula, speed = ((STRIDE_LENGTH / LEG_LENGTH) - 1) * SQRT(LEG_LENGTH * g)
Where g = 9.8 m/s^2 (gravitational constant)
Write a program to read in the data files from disk, it must then print the names of only the bipedal dinosaurs from fastest to slowest.
Interview Answers
I got the exact same question, GOD this was long
in python, using heapq (min heap):
read file 1, add dinos to a dict where name is the key for an object where the field names are keys.
read file 2, skip dinos not in file 1, calculate speed and add to heap as (-speed, name)
while heap, pop min.
Create a class Dinosour - class variables are name, and speed
Create a map by parsing file 2 and adding key as Dinosour name and value as stride length. Only add Dinosour where stance(string split[2] == bipedal)
Create a List , populate the list by parsing file1 , split using string split and only process Dinosours which are present in map. Calculate the speed using formula and create a new Dinosour object (name and speed).
Create a comparator mycmp .( do comparison based on speed of Dinosour object, if speed is same then compare based on name).
Sort the list based on the comparator. Print the list.