Professor X wants his students to help each other in the chemistry lab. He suggests that every student should help out a classmate who scored less marks than him in chemistry and whose roll number appears after him. But the students are lazy and they don't want to search too far. They each pick the first roll number after them that fits the criteria. Find the marks of the classmate that each student picks. If a student is unable to find anyone print -1. Note: one student may be selected by multiple classmates. Input: First line of input contains number of testcases T. For each testcase, there will be two lines, first of which contains N denoting the number of students in the class. Second line contains N space separated integers denoting the marks of each student roll number wise. Output: For each roll number, print the marks of the student he choses to help. Your Task: Complete the function help_classmate() that takes array containing marks and integer N as input parameters and returns a list of integers containing the marks of the classmate that each roll number selects. Constraints:  1 <= T <= 100 1 <= N <= 10^6 Example: Sample Input: 2 5 3 8 5 2 25  4 1 2 3 4  Sample Output: 2 5 2 -1 -1 -1 -1 -1 -1  Explanation: Testcase 1: Roll number 1 has 3 marks. The first person who has less marks than him is roll number 4, who has 2 marks. Roll number 2 has 8 marks, he helps student with 5 marks. Roll number 3 has 5 marks, he helps student with 2 marks. Roll number 4 and 5 can not pick anyone as no student with higher roll number has lesser marks than them. This is denoted by -1. Output shows the marks of the weaker student that each roll number helps in order. ie- 2,5,2,-1,-1 Testcase 2: As the marks ars in increasing order. None of the students can find a classmate who has a higher roll number and less marks than them.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Professor X wants his students to help each other in the chemistry lab. He suggests that every student should help out a classmate who scored less marks than him in chemistry and whose roll number appears after him. But the students are lazy and they don't want to search too far. They each pick the first roll number after them that fits the criteria. Find the marks of the classmate that each student picks. If a student is unable to find anyone print -1.
Note: one student may be selected by multiple classmates.

Input:
First line of input contains number of testcases T. For each testcase, there will be two lines, first of which contains N denoting the number of students in the class. Second line contains N space separated integers denoting the marks of each student roll number wise.

Output:
For each roll number, print the marks of the student he choses to help.

Your Task:
Complete the function help_classmate() that takes array containing marks and integer N as input parameters and returns a list of integers containing the marks of the classmate that each roll number selects.

Constraints: 
1 <= T <= 100
1 <= N <= 10^6

Example:
Sample Input:

2
5
3 8 5 2 25 
4
1 2 3 4 

Sample Output:
2 5 2 -1 -1
-1 -1 -1 -1 

Explanation:
Testcase 1:

Roll number 1 has 3 marks. The first person who has less marks than him is roll number 4, who has 2 marks.
Roll number 2 has 8 marks, he helps student with 5 marks.
Roll number 3 has 5 marks, he helps student with 2 marks.
Roll number 4 and 5 can not pick anyone as no student with higher roll number has lesser marks than them. This is denoted by -1.
Output shows the marks of the weaker student that each roll number helps in order. ie- 2,5,2,-1,-1

Testcase 2:
As the marks ars in increasing order. None of the students can find a classmate who has a higher roll number and less marks than them.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Topological Sort
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education