ThoughtWorks Interview Question for Applications Developers


Country: India
Interview Type: Written Test




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

The answer is given in the question: student 3 obviously has the highest marks and it would be wrong to average out the scores between 1 and 2 because they are equal. Which means if 3 is are baseline and 65 is high then person 1 also scored 65 which is higher than person 2.

- Amanda December 13, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Just a thought process, about to enter under-grad school, however, what I can make of this problem is creating a data structure(lets say Sets) for every subject.
First thing is what is the total marks of each test.
For eg: If subject 1 total marks = 100, we can subtract each obtained score from 100, and the answer we get can be entered in a set. For eg: 100 - 20 = 80,
80 enters the set, and then we check the second students score and subtract it from 100, and we get 65.
We compare 65 to 80 which is already in the set, as 65 less than 80, we can regard the score of second student higher than first student.
Do the same with the third student.

Just a thought process and an idea.

- madebyon December 13, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

marks = {"student1":[20,40,65],"student2":[35,40,50],"student3":[10,55,65]}

for i,k in zip(marks.keys(),marks.values()):
	marks[i] = sum(sorted(k,reverse=True)[:2])

print sorted(marks,key=marks.__getitem__,reverse=True)[:2]

- Harish Hirekandodimatt December 14, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

marks = {"student1":[20,40,65],"student2":[35,40,50],"student3":[10,55,65]}

for i,k in zip(marks.keys(),marks.values()):
marks[i] = sum(sorted(k,reverse=True)[:2])

print sorted(marks,key=marks.__getitem__,reverse=True)[:2]

- Harish Hirekandodimatt December 14, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Sorting is not an entirely good idea here,
we do not need it. We can solve it w/o sorting, and in linear time.
Specifically, we can solve it in 2n, in fact, we can solve it in exact n, e.g. in a single traversal. But first, I would showcase 2n in ZoomBA :

data = [ [ 'Student1', 20, 40, 65], 
         [ 'Student2', 35, 40, 50], 
         [ 'Student3', 10, 55, 65] ]
// for 3 subjects... can be generalized ... 
max = list([0:3]) -> { -1 } // hoping scores do not become -ve
max = fold ( data , max ) ->{
  row = $.o ; max = $.p 
  for ( i = 1 ; i < 4 ; i += 1 ){
    if ( row[i] > max[i-1] ){
      max[i-1] = row[i]
    }
  }
  max // return 
}
// next, pick and group toppers student -> topped_in_sub_count 
// select those who are topper in more than n subjects ?
n = 2 
toppers = fold( data ) -> {
  row = $.o 
  count = sum ( [1:4] ) -> { row[$.o] == max[$.i] ? 1 : 0 }
  continue ( count < n ) // ignore when count is < n 
  [ row[0] , count ] // return 
}
println( toppers )

- NoOne December 14, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Take max marks from each subject with studentName
2. create one map <StudentName, count of subject having max mark)
3. now iterate over max marks and increase the count of subject having max marks in map.
4. iterate over map and find all those having count >=n.

- Avinash Kumar December 19, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

object Misc {

def main (args:Array[String]) {

// Student1 20 40 65
// Student2 35 40 50
// Student3 10 55 65
// Given n = 2.
// Find the name of the students who has got top marks in at least n subjects.
val warehouseLocation = "file:${system:user.dir}/spark-warehouse";
val sparkSession = SparkSession.builder().appName("SparkUseCaseLearning").master("local")
.config("spark.sql.warehouse.dir", warehouseLocation)
.enableHiveSupport().getOrCreate();

import sparkSession.sqlContext.implicits._;
val studentMarksDF = Seq((20,40,65),(35,40,50),(10,55,65)).toDF("sub1","sub2","sub3");
val totalMarksDF = studentMarksDF.withColumn("Total", $"sub1"+$"sub2"+$"sub3").orderBy($"Total".desc);
totalMarksDF.show();
// +----+----+----+-----+
// |sub1|sub2|sub3|Total|
// +----+----+----+-----+
// | 10| 55| 65| 130|
// | 20| 40| 65| 125|
// | 35| 40| 50| 125|
// +----+----+----+-----+

println(totalMarksDF.head())
// [10,55,65,130]

}
}

- Aviral Srivastava June 18, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

object Misc {
  
  def main (args:Array[String]) {

//    Student1 20 40 65
//    Student2 35 40 50
//    Student3 10 55 65
//    Given n = 2.
//    Find the name of the students who has got top marks in at least n subjects.
    val warehouseLocation = "file:${system:user.dir}/spark-warehouse";
    val sparkSession = SparkSession.builder().appName("SparkUseCaseLearning").master("local")
                          .config("spark.sql.warehouse.dir", warehouseLocation)
                          .enableHiveSupport().getOrCreate();
    
    import sparkSession.sqlContext.implicits._;
    val studentMarksDF = Seq((20,40,65),(35,40,50),(10,55,65)).toDF("sub1","sub2","sub3");
    val totalMarksDF = studentMarksDF.withColumn("Total", $"sub1"+$"sub2"+$"sub3").orderBy($"Total".desc);
    totalMarksDF.show();
//    +----+----+----+-----+
//    |sub1|sub2|sub3|Total|
//    +----+----+----+-----+
//    |  10|  55|  65|  130|
//    |  20|  40|  65|  125|
//    |  35|  40|  50|  125|
//    +----+----+----+-----+

    println(totalMarksDF.head())
//    [10,55,65,130]
    
  }
}

- Aviral Srivastava June 18, 2017 | 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