High Score Kit: Stack&Queue#2
Feature Improvement Task
wordsCount: 524
readingTime: 3 mins
viewers:
Problem
The Programmers team is currently performing feature improvement tasks. Each feature can only be released when its progress reaches 100%. However, since the development speed of each feature varies, it is possible for features developed later to be completed earlier. In such cases, a feature that is developed later will be released together with the feature in front of it that is scheduled for earlier release.
Given an integer array progresses
which represents the current progress of each task and an integer array speeds
which represents the daily development speed of each task, implement a function solution
that returns an array indicating how many features are released together on each release day.
Constraints
- The number of tasks (
length of progresses and speeds
) is no more than 100. - Task progress is a natural number less than 100.
- Task speed is a natural number up to 100.
- Deployment can only happen once per day and occurs at the end of the day. For example, if a task is 95% complete and progresses at a rate of 4% per day, it will be deployable in 2 days.
Example
progresses | speeds | return |
---|---|---|
[93, 30, 55] | [1, 30, 5] | [2, 1] |
[95, 90, 99, 99, 80, 99] | [1, 1, 1, 1, 1, 1] | [1, 3, 2] |
Explanation of Examples
-
Example #1:
- The first feature is 93% complete and progresses at 1% per day, thus it takes 7 days to complete.
- The second feature is 30% complete and progresses at 30% per day, thus it takes 3 days. However, it must wait for the first feature to be deployed, hence it is deployed on the 7th day along with the first feature.
- The third feature is 55% complete and progresses at 5% per day, thus it takes 9 days.
- As a result, on the 7th day, 2 features are deployed and on the 9th day, 1 feature is deployed.
-
Example #2:
- All features progress at 1% per day. The remaining days for the tasks to be completed are 5 days, 10 days, 1 day, 1 day, 20 days, and 1 day, respectively.
- Even if a feature is completed, it cannot be deployed until all the preceding features are also ready for deployment.
- Therefore, 1 feature is deployed on the 5th day, 3 features on the 10th day, and 2 features on the 20th day.
How to Approach?
Step1: Initialize variables in loop
Step2: Array copy and sort
Step3: Designate elements to output array
Code
|
|
Table of Contents
Related Posts
High Score Kit: Stack&Queue#1
Problem Given an array arr consisting of integers ranging from 0 to 9, the task is to remove consecutive duplicates while preserving the order of the remaining elements. For instance, if arr = [1, 1, 3, 3, 0, 1, 1], the result should be [1, 3, 0, 1]. Similarly, for arr = [4, 4, 4, 3, 3], the result should be [4, 3].
2024-4-10
High Score Kit: Greedy#1
Problem Given a number, your task is to remove k digits from the number in such a way that the remaining digits form the largest possible number. The number is provided as a string number and the integer k represents the number of digits to remove. Your function solution should return the resulting largest number as a string.
2024-4-11
High Score Kit: DFS&BFS#2
Problem In the ROR game, you play on a team that competes to destroy the opposing team’s base first, making it advantageous to reach the enemy base as quickly as possible. Suppose you’re a team member and are located at position (row: 1, column: 1) on a 5x5 map, while the enemy base is at (row: 5, column: 5).
2024-4-11
High Score Kit: DFS&BFS#1
Problem You are given an array of non-negative integers and a target number. Your task is to find how many ways you can add and subtract the given numbers to achieve the target number. The order of numbers in the array must be preserved. For example, with the array [1, 1, 1, 1, 1], there are five ways to reach the target number 3:
2024-4-11
High Score Kit: Brute Force#2
Problem In a power grid network composed of n transmission towers connected in a tree structure via wires, you are tasked with dividing the network into two parts by cutting one of the wires. The goal is to make the number of transmission towers in each part as equal as possible.
2024-4-11
High Score Kit: Brute Force#1
Problem In the XX game, there is a fatigue system represented by non-negative integers, allowing players to explore dungeons by using a certain amount of fatigue. Each dungeon requires a “minimum required fatigue” to start exploring and consumes a certain amount of “fatigue” upon completion. For example, to explore a dungeon with a “minimum required fatigue” of 80 and a “consumption fatigue” of 20, a player’s current remaining fatigue must be at least 80, and it will decrease by 20 after exploring the dungeon.
2024-4-11
Sponsor
Wechat
Alipay