- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions

# Program to find minimum space plane required for skydivers in k days in python

Suppose we have a list of numbers called nums where each value represents a group of people looking to skydive together. And we have another value k representing how many days they can apply for skydiving. We have to find the minimum capacity of the plane we need to be able to fulfill all requests within k days. The requests should be fulfilled in the order they were given and a plane can only fly once a day.

So, if the input is like nums = [16, 12, 18, 11, 13], k = 3, then the output will be 28, as 28-person airplane can group the given requests by [16, 12], [18], [11, 13].

To solve this, we will follow these steps −

- if nums is empty, then
- return 0

- start := maximum of nums, end := sum of all elements of nums
- while start < end, do
- mid := (start + end) / 2
- days := 1, temp := 0
- for each num in nums, do
- if temp + num > mid, then
- days := days + 1
- temp := num

- otherwise,
- temp := temp + num

- if temp + num > mid, then
- if days > k, then
- start := mid + 1

- otherwise,
- end := mid

- return start

Let us see the following implementation to get better understanding −

## Example

class Solution: def solve(self, nums, k): if not nums: return 0 start, end = max(nums), sum(nums) while start < end: mid = (start + end) // 2 days = 1 temp = 0 for num in nums: if temp + num > mid: days += 1 temp = num else: temp += num if days > k: start = mid + 1 else: end = mid return start ob = Solution() nums = [16, 12, 18, 11, 13] k = 3 print(ob.solve(nums, k))

## Input

[16, 12, 18, 11, 13], 3

## Output

28

- Related Articles
- Program to find minimum bus fare for travelling all days in Python?
- Program to find minimum changes required for alternating binary string in Python
- Program to find minimum required chances to form a string with K unique characters in Python
- Program to find minimum adjacent swaps for K consecutive ones in Python
- Program to find minimum number of bricks required to make k towers of same height in Python
- Program to find minimum sum of difficulties to complete jobs over k days in C++
- Program to find minimum swaps required to make given anagram in python
- Program to find minimum remove required to make valid parentheses in Python
- Program to find minimum time required to complete tasks with k time gap between same type tasks in Python
- Program to find minimum cost to hire k workers in Python
- Program to find state of prison cells after k days in python
- Program to find minimum number of days to eat N oranges in Python
- C++ Program to find minimum k for candy distribution
- Program to find minimum amplitude after deleting K elements in Python
- Program to find minimum number of days to wait to make profit in python

Advertisements