📣 黑五价提前开抢|VIP一年通行证5折,蓝莓、Offer多多同步特惠
回复: 0
跳转到指定楼层
上一主题 下一主题
收起左侧

🍌OA 5月高频题

全局:

2025(4-6月) 码农类General 硕士 全职@amazon - 猎头 - 在线笔试  | 😐 Neutral 😐 Average | WaitList | 在职跳槽

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x

两道题地里前几天都有人发布过,可惜我没认真准备答案

1.
There are n chapters to be studied where the ith chapter has pages[i] pages. In one day, the student decides to read up to p of the remaining pages, each from some k consecutive chapters. Thus, the number of pages remaining to be read is reduced by p from each of these chapters. If a chapter has less than p pages remaining, the student reads the remaining pages, and the remaining page count is set to 0 for subsequent days. Find the minimum number of days the student needs to read all the chapters completely, i.e., the remaining page count of all chapters is 0.
Note: The chapters read must be contiguous. Example: The number of chapters is n = 3, the number of chapters read in a day is k = 2, the number of pages read from each chapter is p = 2, and the page counts of each chapter are pages = [3, 1, 4]. The chapters can be read as follows: Choose chapters 1 and 2, remaining pages to be read = [1, 0, 4]. Choose chapters 1 and 2, remaining pages to be read = [0, 0, 4]. Choose chapters 2 and 3, remaining pages to be read = [0, 0, 2]. Finally, choose chapters 2 and 3, remaining pages to be read = [0, 0, 0]. The chapters cannot be read in less than 4 days.
Function Description: Complete the function findMinimumDays in the editor below. findMinimumDays has the following parameters: int pages[n]: the number of pages in each chapter int k: the number of chapters chosen each day int p: the maximum number of pages read from each chapter in a day Returns long_int: the minimum number of days to read all pages of all chapters Constraints: 1 ≤ n ≤ 10^5 1 ≤ pages[i] ≤ 10^9 1 ≤ k ≤ n 1 ≤ p ≤ 10^9 Example 1: pages = [3, 4] k = 1 p = 2 output: 4 read the first chapter for the first two days, and the second chapter for the next two days.

下面解法是双子座给出的:import math



def findMinimumDays(pages: list[int], k: int, p: int) -> int:

    """

    Finds the minimum number of days required to read all chapters.



    Args:

        pages: A list of integers where pages[i] is the number of pages in the i-th chapter.

        k: The number of consecutive c
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
way such that abs(candidate[i] - candidate[i+1])<=1 for 0<=i<m-1 and abs(candidate[m-1] - candidate[0]) <= 1. Find the maximum number of servers the client can buy from the n available servers

下面解法是ChatGPT给出的from collections import Counter



def getMaxServers(powers):

    count = Counter(powers)

    uniq = sorted(count.keys())

    max_len = 0

    left = 0



    # 滑动窗口右边界

    for right in range(len(uniq)):

        # 如果当前窗口不连续,重置左边界

        if right > 0 and uniq[right] != uniq[right - 1] + 1:

            left = right



        # 检查当前窗口是否满足构造条件

        valid = True

        if right - left + 1 >= 3:

            for mid in range(left + 1, right):  # 中间值必须出现 >=2 次

                if count[uniq[mid]] < 2:

                    valid = False

                    break

        if valid:

            # 计算当前窗口长度(所有值的总数)

            total = sum(count[uniq[i]] for i in range(left, right + 1))

            max_len = max(max_len, total)



    # 单独考虑一个值的情况(例如很多个2)

    for val in count.values():

        max_len = max(max_len, val)



    return max_len



# 示例测试

powers = [7,2,2,3,2,1,2,2]

print(getMaxServers(powers))  # 输出应为 7

评分

参与人数 1大米 +15 收起 理由
匿名用户-YW9UQ + 15 欢迎分享你知道的情况,会给更多大米奖励!

查看全部评分


上一篇:COINBASE OA之差点翻车
下一篇:DD onsite 最近有过的吗?
您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表