Skip to main content
Practice

coding-quiz-6

---
id: coding-quiz-6
title: Coding Quiz - Gym Uniform Problem
description: Write a function to solve the gym uniform problem using a greedy algorithm.
tags:
- Python
- Greedy
- Algorithm
- Function
sidebar_position: 11
isPublic: false
---

# 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`.

<br />

```python title="Code Implementation"
def solution(n, lost, reserve):
# Write your code here
return



Constraints

  • The total number of students is between 2 and 30.

  • 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

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.