楼主: 匿名
跳转到指定楼层
上一主题 下一主题
收起左侧

胡萝卜Instacart的虚拟现场表演

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

使用道具 举报

🔗
泰拳大师 2021-3-28 06:30:50 | 只看该作者
全局:
woshilxd912 发表于 2020-11-10 14:15
写了一个Java的O(n)解法,输出所有可能组合,如果只输出一个,那找到任何一个满足的时候,返回即可。

[m ...

card可能的组合一共就27种,map最多也就27个entry,这个27*n真的比n^2优化么
回复

使用道具 举报

🔗
woshilxd912 2021-3-29 09:13:44 | 只看该作者
全局:
泰拳大师 发表于 2021-3-28 06:30
card可能的组合一共就27种,map最多也就27个entry,这个27*n真的比n^2优化么

肯定吧,O(n) 比 O (n^2) 怎么说都是更优化的。
回复

使用道具 举报

🔗
fanttfw_2020 2021-4-12 11:02:30 | 只看该作者
全局:
yinshan8 发表于 2020-6-16 02:54
因为 [5,6] 那行上面有一个1, 表示第一行,【5,6】表达 字符的index

1

are you sure?
回复

使用道具 举报

🔗
winkyue 2021-4-15 11:12:10 | 只看该作者
全局:
大家都怎么做payment service? 为什么信用卡能搞出一个http request? 什么时候拒绝刷钱?
回复

使用道具 举报

🔗
winkyue 2021-4-15 11:14:02 | 只看该作者
全局:

左下角是(0,0), row number是6, column number是5
回复

使用道具 举报

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

使用道具 举报

🔗
iuysyjdmuvew 2021-6-24 13:26:52 | 只看该作者
全局:
泰拳大师 发表于 2021-3-28 06:29
问题是,card可能的组合一共就27种,这个27*n真的比n^2优化么

对哦。。哈哈哈哈 这不就是所有解法都是O(1)吗
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-Q6XGA  2023-7-12 08:06:34
冒个泡,分享一下自己对于card game的解法。时间复杂度就是27^3
  1. private static List<List<String>> cardGames(String[] cards) {
  2.     String prefixes = "+-=";
  3.     int[] cnt = new int[]{1, 2, 3};
  4.     String[] letters = new String[]{"A", "B", "C"};
  5.     boolean[][][] dict = new boolean[3][3][3];
  6.     for (String card : cards) {
  7.         int prefixIdx = prefixes.indexOf(card.charAt(0));
  8.         int letterIdx = card.charAt(1) - 'A';
  9.         int letterCnt = card.length() - 2; // 0-based length, 0 value means length 1
  10.         dict[prefixIdx][letterIdx][letterCnt] = true;
  11.     }
  12.     List<List<String>> ans = new ArrayList<>();
  13.     // find a point in the above 3x3x3 cube where either all coord (x,y,z) is the same or all different.
  14.     for (int i=0; i<27; i++) {
  15.         int card1_y = (i % 9) / 3, card1_x = (i % 9) % 3, card1_z = i / 9; // note y is the row
  16.         if (!dict[card1_x][card1_y][card1_z]) continue;
  17.         for (int j=i; j<27; j++) {
  18.             int card2_y = (j % 9) / 3, card2_x = (j % 9) % 3, card2_z = j / 9; // note y is the row
  19.             if (!dict[card2_x][card2_y][card2_z]) continue;
  20.             for (int k=j; k<27; k++) {
  21.                 int card3_y = (k % 9) / 3, card3_x = (k % 9) % 3, card3_z = k / 9; // note y is the row
  22.                 if (!dict[card3_x][card3_y][card3_z]) continue;
  23.                 boolean equalY = card1_y == card2_y && card1_y == card3_y;
  24.                 boolean equalX = card1_x == card2_x && card1_x == card3_x;
  25.                 boolean equalZ = card1_z == card2_z && card1_z == card3_z;
  26.                 boolean allDiffY =  (card1_y + card2_y + card3_y) == 3;
  27.                 boolean allDiffX =  (card1_x + card2_x + card3_x) == 3;
  28.                 boolean allDiffZ =  (card1_z + card2_z + card3_z) == 3;
  29.                 if ((allDiffX || equalX) && (allDiffY || equalY) && (allDiffZ || equalZ)) {
  30.                     ans.add(Arrays.asList(restoreCard(card1_x, card1_y,card1_z),
  31.                     restoreCard(card2_x, card2_y, card2_z),
  32.                     restoreCard(card3_x, card3_y, card3_z)));
  33.                 }
  34.         }
  35.     }
  36.         }
  37.         return ans;
  38.     }

  39.     private static String restoreCard(int prefix, int letter, int freq) {
  40. <b>    </b>String prefixes = "+-=";
  41.     int[] cnt = new int[]{1, 2, 3};
  42.     String[] letters = new String[]{"A", "B", "C"};
  43.     StringBuilder card = new StringBuilder();
  44.     card.append(prefixes.charAt(prefix));
  45.     while (freq >= 0) {
  46.         card.append(letters[letter]);
  47.         freq--;
  48.     }
  49.     return card.toString();
  50.     }
复制代码
回复

使用道具 举报

🔗
Gigas 2024-7-14 06:27:22 | 只看该作者
全局:
本帖最后由 Gigas 于 2024-7-13 15:35 编辑

请问楼主这个set of cards 题目有follow up吗
回复

使用道具 举报

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

本版积分规则

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