回复: 6
跳转到指定楼层
上一主题 下一主题
收起左侧

空气床 电面

🔗
匿名用户-MCTLU  2021-3-12 08:01:23 |倒序浏览

2021(1-3月) 码农类General 硕士 全职@airbnb - 网上海投 - 技术电面  | | WaitList | 在职跳槽

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

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

x
电面题目如同:

今天(Mar 11) 刚
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
CUZ_CODE_0        ]

评分

参与人数 5大米 +14 收起 理由
渣渣程序员 + 3 给你点个赞!
user2198M + 1 给你点个赞!
lexiedj + 1 给你点个赞!
wxliuyizhe + 1 赞一个
匿名用户-WOVJU + 8

查看全部评分


上一篇:外卖公司过经
下一篇:黑车公司过经
推荐
abcde1996 2021-5-15 02:05:17 | 只看该作者
全局:
是不是没考虑   比如 num 12000  Lower Bound 200.。。。Leading Zero
回复

使用道具 举报

🔗
ljbschen 2021-3-15 18:14:12 | 只看该作者
全局:
本帖最后由 ljbschen 于 2021-3-15 18:16 编辑

感觉好长啊.. 楼主的解法时间复杂度怎样啊
感觉直接暴力back tracking就可以了. 30行不到..就是n^m看着不好...
回复

使用道具 举报

🔗
小牧 2021-3-26 23:59:03 | 只看该作者
全局:
调一个all permutation 就可以了
在 base case 里面做一些文章而已  为了少一点参数,全部global了。
理解意思就好。
关于时间复杂度,因为只要找到就可以提前终止 recursion 了, 这里没写,在base case里只要find,throw exception 的方式终止。类似 break loop。
  1. public class FindSmallestPermutationK {
  2.     int num;
  3.     int lowerBound;
  4.     int res;
  5.     boolean find;
  6.     public int findSmallPer(int num, int lowerBound) {
  7.         this.num = num;
  8.         this.lowerBound = lowerBound;
  9.         this.res = Integer.MIN_VALUE;
  10.         this.find = false;

  11.         char[] array = Integer.toString(num).toCharArray();
  12.         Arrays.sort(array);
  13.         allPermutation(array, 0, array.length);
  14.         return res;
  15.     }

  16.     private void allPermutation(char[] array, int index, int n) {
  17.         if (index == n) {
  18.             int cur = Integer.parseInt(new String(array));

  19.             if (!find && cur > num && cur > lowerBound) {
  20.                 res = cur;
  21.                 find = true;
  22.             }
  23.             return;

  24.         }

  25.         for (int i = index; i < n; i++) {
  26.             swap(array, i, index);
  27.             allPermutation(array, index + 1, n);
  28.             swap(array, i, index);
  29.         }
  30.     }

  31.     private void swap(char[] array, int a, int b) {
  32.         char temp = array[a];
  33.         array[a] = array[b];
  34.         array[b] = temp;
  35.     }


  36.     public static void main(String[] args) {
  37.         FindSmallestPermutationK sol = new FindSmallestPermutationK();
  38.         System.out.println(sol.findSmallPer(4319, 200));
  39.         System.out.println(sol.findSmallPer(123, 100));
  40.         System.out.println(sol.findSmallPer(123, 911));
  41.         System.out.println(sol.findSmallPer(12378, 12456));
  42.         System.out.println(sol.findSmallPer(12345, 12678));
  43. //        System.out.println(sol.findSmallPer(123, 911));
  44.     }
  45. }
复制代码
[/b][/b]
回复

使用道具 举报

🔗
yikesaiting 2021-6-4 03:55:03 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

🔗
zhangxiaokun 2021-7-29 04:29:50 | 只看该作者
全局:
请问LZ申请的什么level呀
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-SYLRG  2021-8-27 02:08:33
请问楼主,这个题如果0 能放在leading 吗? 比如1200, lower bound 200, 应该return 1002 还是201? 如果是1002, 那么这个code 好像不支持
回复

使用道具 举报

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

本版积分规则

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