Akamai Interview Question
Country: India
Interview Type: Phone Interview
In scala i would use plain class list and filter function. Complexity is linear O(n)
type Exam = (String, Double)
val subjectToSearch = "Math"
val minimumPassing = 60.0
case class Student(val id: String, val name: String, val age: Int, val exams: List[Exam]) {
}
val students = List[Student](
Student("1", "1", 18, List(("English",20.34),("Math",84.5))),
Student("2", "1", 18, List(("English",30.34),("History",74.5))),
Student("3", "1", 18, List(("English",40.34),("History",64.5))),
Student("4", "1", 18, List(("English",50.34),("History",54.5))),
Student("5", "1", 18, List(("English",60.34),("Math",64.5))),
Student("6", "1", 18, List(("English",70.34),("Math",34.5))),
Student("7", "1", 18, List(("English",80.34),("History",24.5)))
)
students.filter(curStudent => curStudent.exams.filter(exam => exam._2>minimumPassing && exam._1.equalsIgnoreCase(subjectToSearch)).size > 0)
Create binary trees, one for each subject. The node contains a score, a set of students for that score, and children (which are nodes) for values below the score and above it.
class SubjectTree {
int score;
Set<Student> students = new Set<Student>();
SubjectTree lesser;
SubjectTree greater;
}
Don't reinvent the wheel, put your data into a database and query your data using sql.
- cjudge@grandecom.net May 02, 2017