Hatori's Parade Student Selection

Hatori, the class teacher, has 'N' students and aims to select the maximum number of students for the Republic Day parade. The condition for selection is that the absolute difference in the heights of any two students in the group should not exceed 5.

Input:

1. An integer 'T' indicating the number of test cases. 2. For each test case: - An integer 'N' representing the number of students. - A list of 'N' space-separated integers representing the heights of the students.

Output:

For each test case, output the maximum number of students that can be selected. Each result should be printed on a new line.

Example:

Input:
T = 1
N = 7
H = [1, 6, 7, 8, 2, 3, 11]
Output:
4
Explanation:

To maximize selection, students with heights 6, 7, 8, and 11 can be picked as their height differences do not exceed 5.

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 105
  • 1 <= H[i] <= 109

Time Limit: 1 sec

AnswerBot
1mo

The task is to select the maximum number of students for a parade based on height constraints.

  • Iterate through the list of heights and sort them.

  • Use two pointers technique to find the maximum number of...read more

Help your peers!
Add answer anonymously...
Wipro Project Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter