Coding Quiz - Gym Uniform Problem
In this coding quiz, you will write a program to solve the "gym uniform problem" using a Greedy Algorithm.
The scenario for this problem is as follows: Students are given gym uniforms for physical education classes at school.
However, some students have lost their uniforms, and some kind students have brought extra uniforms.
A student with extra uniforms can lend them only to a student with the immediately preceding or following number.
The goal is to decide how to distribute the uniforms in order to minimize the number of students who need a uniform.
def solution(n, lost, reserve): # Write your code here return
Constraints
-
The total number of students is between
2and30. -
The number of students who lost uniforms and those who brought extra uniforms is at least 1 and no more than the number of students.
-
A student who has brought an extra uniform may also lose their own, and in this case, they cannot lend a uniform to another student.
Input/Output Example
-
Input:
n = 5, lost = [2, 4], reserve = [1, 3, 5] -
Output:
5
Lessons in this chapter · Practice with Common Coding Quiz Types
- 1. Coding Quiz - Finding Rotten Apples
- 2. Finding Rotten Apples Explained
- 3. Coding Quiz - Calculating the Sum of a List Recursively
- 4. Explanation for Recursively Calculating the Sum of a List
- 5. Coding Quiz - 1, 2, 3 Addition
- 6. Explanation for Adding 1, 2, 3
- 7. Coding Quiz - Flattening a 2D Array
- 8. Converting to a 1D Array Explanation
- 9. Coding Quiz - Calculate the Sum of a List Using Divide and Conquer
- 10. Explanation of Calculating the Sum of a List Using Divide and Conquer
- 11. Coding Quiz - Gym Uniform Problem
- 12. Gym Uniform Problem Explanation
- 13. Coding Quiz - List of Integers with Sum Greater than Target
- 14. Explanation of Integer List with Sum Greater Than Target
- 15. Coding Quiz - Finding Travel Routes
- 16. Finding Travel Itinerary Explanation
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help