当前位置:首页|资讯

GFG 94 Least Beautiful Box

作者:您是打尖儿还是住店呢发布时间:2024-09-24

An array of length n denotes the id of the i ice cream Geek has bought to celebrate his birthday. 

Now out of nowhere, he wants to divide them into different boxes such that in each box the id of

the ice creams can be represented as a sequence of consecutive integers. The beauty of a box is

de ned as the number of ice creams present in that. 


Please help Geek to find an arrangement such that beauty of least beautiful box is maximized.


Example 1:


Input:

n = 9

id = [5, 1, 3, 2, 2, 4, 3, 4, 1]


Output:

4


Explanation:

The arrangement geek will choose is -

[1, 2, 3, 4, 5]

[1, 2, 3, 4]

It can be shown that there does not exist any other arrangement of the ice creams

such that the beauty of least beautiful box is greater than 4.


Example 2:


Input:

n = 5

id = [4, 5, 6, 6, 7]


Output:

2


Explanation:

The arrangement geek will choose is


[4, 5, 6]

[6, 7] It can be shown that there does not exist any other arrangement of the ice creams

such that the beauty of least beautiful box is greater than 2.


Your Task:

You don't need to read input or print anything. Your task is to complete the

function minimumBeauty() which accepts the ids of the ice creams and number of ice creams as

the input and returns the maximum possible beauty of the room with least beauty.


Constraints:

0 < n <= 10

0 < id[i] <= 10

-------

每次新建一个list,然后加进去最小的值,然后只要后面k+1出现的次数大于等于k出现的次数的话,就可以把k+1加到list中。

加完之后,更新min的大小,以及map,把list中的数去掉,如果value=0,那么删除该元素,

没想到自己想想就能把40分的题目做出来。不看题解的情况下。。



Copyright © 2024 aigcdaily.cn  北京智识时代科技有限公司  版权所有  京ICP备2023006237号-1