<
回复: 8
收起左侧

字节跳舞近期面经总结

   
匿名用户-VLBLT  2023-9-30 10:07:59 来自APP
本楼:   👍  9
100%
0%
0   👎

2023(7-9月) 码农类General 硕士 全职@字节跳动 - 内推 - 技术电面 Onsite  | 🙁 Negative 😐 AverageFail | 在职跳槽
本帖最后由 匿名 于 2023-9-29 21:09 编辑

leetcode 原题:





题目:
Given an array nums which consists of only '0's and '1's where '1' denotes there's a stone at a given position, an index p, and an integer k. Find the minimum steps needed to stack at least k stones at position p. Within one step, you're only allowed to move one stone to an adjacent position.
# nums: [1,0,1,0,0,1]
# k: 2
# p: 2
# result=2
Followup:# Given an array nums which consists of only '0's and '1's where '1' denotes there's a stone at given position, and an integer k. Find the minimum steps needed to stack at least k stones. Within one step, ‍‍‌‌‌‌‌‍‍‍‍‌‌‌‍‍‍‍‍you're only allowed to move one stone to an adjacent position.
解题:
public static int move(int[] stones, int k, int p){
        if(k <= 0)
            return 0;
        if(p >= stones.length)
            return -1;

        // int index = 0;
        // for(int i=0; i <stones.length;i++){
        //     if(stones[i] == 1)
        //         stones[index++] = i;
        // }
        // if(index < k)
        //     return -1;
        // int[] presum = new int[index];
        // presum[0] = stones[0];
        // for(int j=1;j < index;j++){
        //     presum[j] += presum[j-1] + stones[j];
        // }
        // int result = Integer.MAX_VALUE;
        int remain = k - stones[p];
        int steps = 0;
        int l=p-1,r=p+1;
        while(remain > 0){
            if(l >=0 && stones[l] == 1 && remain > 0){
                steps +=(p -l);
                remain--;

            }

            if(stones[r] == 1 && r < stones.length && remain > 0){
                steps += (r - p);
              
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
blank">https://blog.csdn.net/qq_46105170/article/details/117814799
第三题:
有一个 linklist 5 - 3 - 2, - 4 - 1 - 8 - 2 - 1 - 3 - 4 - 6, 和 target 3 给出一个新的linklist 是由 小于 target 等于 target 大于 ta‍‍‌‌‌‌‌‍‍‍‍‌‌‌‍‍‍‍‍rget 拼在一起
比如说 上面 output 就是 2 - 1 - 2 - 1 - 3 - 3 - 5 - 4 - 8 - 4 - 6
        解题:定义三个临时头节点,然后while loop

sd题目:


补充内容 (2023-09-30 10:11 +08:00):

第一次排版有点乱。

本帖子中包含更多资源

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

x

评分

参与人数 17大米 +39 收起 理由
无数鱼 + 1 很有用的信息!
wutonghuahua + 1 欢迎分享你知道的情况,会给更多积分奖励!
小魏Stenica + 1 给你点个赞!
billgates5566 + 2 给你点个赞!
Max_well + 2 很有用的信息!

查看全部评分


上一篇:字节跳舞第一轮
下一篇:雪花店面第二轮
pumazda 2023-10-3 01:25:16 | 显示全部楼层
本楼:   👍  1
100%
0%
0   👎
全局:   12
100%
0%
0
楼上几个不厚道,加米了
回复

使用道具 举报

地里匿名用户
匿名用户-XHD63  2023-10-1 14:20:29 来自APP
本楼:   👍  1
100%
0%
0   👎
匿名用户 发表于 2023-09-30 23:00:53
楼主是新手把,硬刷leetcode?你这解题思路有大毛病啊
啥解题思路?
leetcode就等同于面经吧
回复

使用道具 举报

地里匿名用户
匿名用户-HXN2E  2023-10-1 10:24:05
本楼:   👍  0
0%
0%
0   👎
楼主面了几次?怎么这么多题
回复

使用道具 举报

地里匿名用户
匿名用户-XHD63  2023-10-1 13:49:02 来自APP
本楼:   👍  0
0%
0%
0   👎
请问这是你总结的近期面经吗
回复

使用道具 举报

地里匿名用户
匿名用户-HXN2E  2023-10-1 14:00:53
本楼:   👍  0
0%
100%
3   👎
楼主是新手把,硬刷leetcode?你这解题思路有大毛病啊
回复

使用道具 举报

地里匿名用户
匿名用户-HXN2E  2023-10-1 14:51:51
本楼:   👍  0
0%
0%
0   👎
这就是国内的题吗,第三题是什么意思,啥条件?
回复

使用道具 举报

洛水ti2000 2023-10-1 23:36:53 | 显示全部楼层
本楼:   👍  0
0%
0%
0   👎
全局:   5
83%
17%
1
只是提醒一下,第一题由p点开始向两端搜索就是on的效率了,你第二个思路并没有更快。
回复

使用道具 举报

sgedward365 2023-10-4 07:47:00 | 显示全部楼层
本楼:   👍  0
0%
0%
0   👎
全局:   34
79%
21%
9
楼主面的是什么级别?
回复

使用道具 举报

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

本版积分规则

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