Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

class Solution: def maxRunTime(self, n: int, batteries: List[int]) -> int: Implementation in Python3 Please submit as early as possible You have n computers. You are

image text in transcribedimage text in transcribedimage text in transcribed

class Solution: def maxRunTime(self, n: int, batteries: List[int]) -> int:

Implementation in Python3

Please submit as early as possible

You have n computers. You are given the integer n and a 0-indexed integer array batteries where the ith battery can run a computer for batteries[i] minutes. You are interested in running all n computers simultaneously using the given batteries. Initially, you can insert at most one battery into each computer. After that and at any integer time moment, you can remove a battery from a computer and insert another battery any number of times. The inserted battery can be a totally new battery or a battery from another computer. You may assume that the removing and inserting processes take no time. Note that the batteries cannot be recharged. Return the maximum number of minutes you can run all the n computers simultaneously. Example 1: 2 minutes 1 minute 1 minute IT 0 0 1 2 0 1 2 1 2 Input: n = 2, batteries = [3,3,3] Output: 4 Explanation: Initially, insert battery o into the first computer and battery 1 into the second computer. After two minutes, remove battery 1 from the second computer and insert battery 2 instead. Note that battery 1 can still run for one minute. At the end of the third minute, battery o is drained, and you need to remove it from the first computer and insert battery 1 instead. By the end of the fourth minute, battery 1 is also drained, and the first computer is no longer running. We can run the two computers simultaneously for at most 4 minutes, so we return 4. Example 2: 1 minute 1 minute 0 0 0 1 2 3 1 3 Input: n = 2, batteries = [1,1,1,1] Output: 2 Explanation: Initially, insert battery o into the first computer and battery 2 into the second computer. After one minute, battery o and battery 2 are drained so you need to remove them and insert battery i into the first computer and battery 3 into th After another minute, battery 1 and battery 3 are also drained so the first and second computers are no longer running. We can run the two computers simultaneously for at most 2 minutes, so we return 2. Constraints: 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases A Beginners Guide

Authors: Andy Oppel

1st Edition

007160846X, 978-0071608466

More Books

Students also viewed these Databases questions

Question

Explain consumer behaviour.

Answered: 1 week ago

Question

Explain the factors influencing consumer behaviour.

Answered: 1 week ago

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago