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
2
and30
. -
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
Lecture
AI Tutor
Publish
Design
Upload
Notes
Favorites
Help