713192. Find minimum number of Laptops required

Medium

Find minimum number of Laptops required

Summary

In this problem, we are asked to find the minimum number of laptops required to distribute among a set of students. Each student has a specific requirement for laptops and can be assigned multiple laptops. We need to determine how many laptops should be purchased to meet all the requirements.

The key concepts involved in this problem are sorting and algorithms.

Detailed Explanation

To solve this problem, we will first sort the students' laptop requirements in ascending order. Then, we will iterate through the sorted list and assign laptops until we have met all the requirements. If a student requires more laptops than we have available, we will need to purchase additional laptops to meet their requirement.

Here is the step-by-step breakdown of the solution:

  1. Sort the students' laptop requirements in ascending order.
  2. Initialize a variable laptops_required to keep track of the minimum number of laptops required.
  3. Iterate through the sorted list and assign laptops until we have met all the requirements.
  4. If a student requires more laptops than we have available, increment laptops_required by 1.

The time complexity for this solution is O(n log n) due to the sorting step, where n is the number of students. The space complexity is O(1), as we only use a constant amount of space to store the sorted list and the laptops_required variable.

Optimized Solutions

Java

View on GeeksforGeeks
import java.util.Arrays;

public class Laptops {
    public static int minLaptops(int[] requirements) {
        Arrays.sort(requirements);
        int laptops_required = 0;
        for (int requirement : requirements) {
            if (requirement > laptops_required) {
                laptops_required++;
            }
        }
        return laptops_required;
    }
}

DevExCode

Master coding interviews with Leetcode, system design, TechBit, QuickLearn, DevTips, Tech Battles, and career services.

© 2026 DevExCode. All rights reserved.