12
返回列表 发新帖
楼主: 匿名
跳转到指定楼层
上一主题 下一主题
收起左侧

doordash电面挂经

地里匿名用户
🔗
匿名用户-DB9E6  2024-10-28 08:02:38
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
回复

使用道具 举报

🔗
honeyp0rkbelly 2024-10-29 09:13:32 | 只看该作者
全局:
想问一下面试官initials是EC吗?非常感谢,会加米的🙏
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-DB9E6  2024-10-30 04:19:52
honeyp0rkbelly 发表于 2024-10-28 21:13
想问一下面试官initials是EC吗?非常感谢,会加米的🙏

不是,我的面试官是Ben F。
回复

使用道具 举报

🔗
chipmunks123 2024-11-1 13:28:34 | 只看该作者
全局:
  1. class Solution {
  2.     private int[] pattern;
  3.     private String str;
  4.     private int count = 0;
  5.    
  6.     public int countValidCombinations(int[] pattern, String str) {
  7.         this.pattern = pattern;
  8.         this.str = str;
  9.         backtrack(0, 0, 0);
  10.         return count;
  11.     }
  12.    
  13.     private void backtrack(int strIndex, int patternIndex, int currentFCount) {
  14.         // Base case: reached end of string
  15.         if (strIndex == str.length()) {
  16.             // Valid only if we've used all patterns and current F count is 0
  17.             if (patternIndex == pattern.length && currentFCount == 0) {
  18.                 count++;
  19.             }
  20.             return;
  21.         }
  22.         
  23.         // If current F count matches pattern number, must use W
  24.         if (currentFCount > 0 && patternIndex < pattern.length &&
  25.             currentFCount == pattern[patternIndex]) {
  26.             if (str.charAt(strIndex) != 'F') {
  27.                 backtrack(strIndex + 1, patternIndex + 1, 0);
  28.             }
  29.             return;
  30.         }
  31.         
  32.         // If current F count exceeds pattern number, invalid path
  33.         if (patternIndex < pattern.length && currentFCount > pattern[patternIndex]) {
  34.             return;
  35.         }
  36.         
  37.         char currentChar = str.charAt(strIndex);
  38.         if (currentChar == '?') {
  39.             // Try F
  40.             backtrack(strIndex + 1, patternIndex, currentFCount + 1);
  41.             // Try W
  42.             if (currentFCount == 0 ||
  43.                 (patternIndex < pattern.length && currentFCount == pattern[patternIndex])) {
  44.                 backtrack(strIndex + 1, currentFCount == 0 ? patternIndex : patternIndex + 1, 0);
  45.             }
  46.         } else if (currentChar == 'F') {
  47.             backtrack(strIndex + 1, patternIndex, currentFCount + 1);
  48.         } else { // currentChar == 'W'
  49.             if (currentFCount == 0 ||
  50.                 (patternIndex < pattern.length && currentFCount == pattern[patternIndex])) {
  51.                 backtrack(strIndex + 1, currentFCount == 0 ? patternIndex : patternIndex + 1, 0);
  52.             }
  53.         }
  54.     }
  55.    
  56.     public static void main(String[] args) {
  57.         testCase1();
  58.         testCase2();
  59.         testCase3();
  60.         testCase4();
  61.     }
  62.    
  63.     private static void testCase1() {
  64.         Solution solution = new Solution();
  65.         int[] pattern = {1, 3, 2};
  66.         String str = "FW?FF??W";
  67.         int result = solution.countValidCombinations(pattern, str);
  68.         System.out.println("Test Case 1: " + result);
  69.         // Expected: pattern matches like "FWFFF??W" where ? can be F or W
  70.     }
  71.    
  72.     private static void testCase2() {
  73.         Solution solution = new Solution();
  74.         int[] pattern = {1};
  75.         String str = "F?W";
  76.         int result = solution.countValidCombinations(pattern, str);
  77.         System.out.println("Test Case 2: " + result);
  78.         // Expected: 1 (only "FWW" is valid)
  79.     }
  80.    
  81.     private static void testCase3() {
  82.         Solution solution = new Solution();
  83.         int[] pattern = {2};
  84.         String str = "FF?";
  85.         int result = solution.countValidCombinations(pattern, str);
  86.         System.out.println("Test Case 3: " + result);
  87.         // Expected: 1 (only "FFW" is valid)
  88.     }
  89.    
  90.     private static void testCase4() {
  91.         Solution solution = new Solution();
  92.         int[] pattern = {1, 1};
  93.         String str = "F?F?";
  94.         int result = solution.countValidCombinations(pattern, str);
  95.         System.out.println("Test Case 4: " + result);
  96.         // Expected: 1 (only "FWFW" is valid)
  97.     }
  98. }
复制代码
回复

使用道具 举报

🔗
Hmoon 2024-11-20 16:13:50 | 只看该作者
全局:
匿名用户 发表于 2024-10-27 16:02
对,面试官说造出所有valid patterns再检查是能通过的。不过我想到可以这个做法的时候只剩15分钟了,面试 ...

如果遍历所有condidate pattern 2^K, 然后再检查,这样倒不难。
回复

使用道具 举报

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

本版积分规则

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