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

[字符串] amazon 真题OA: min cost to remove bad phase in password string

全局:

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

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

x
本帖最后由 kenpeter 于 2024-12-9 18:25 编辑

这个是原题


It is a bit long, but I will summarise what is really asking.
  1. test case 1:  

  2. input1, bad phase in password:  
  3. bcb (it can be rearranged as bbc, cbb)  

  4. input2, password:  
  5. abcdcbcb

  6. input3, operation cost:  
  7. [a_2, b_3, c_1, d_4, e_0, f_0..... z_0] (rest are op cost zero)  

  8. our goal is that we don't want bcb or b????c???b (subsequence) appearing in password. Same for bbc, cbb. We will remove each letter with cost and return the min total cost operation.  

  9. may use stack, but I am not sure.  

  10. abcdcbcb -> strip all unrelated chars -> bccbcb  

  11. sample stack dry run  



  12. run 1:  
  13. bad phase:  
  14. bcb  
  15. bbc  
  16. cbb  
  17. [b]  
  18. [bc]  
  19. [bcc]  
  20. [bccb_x] (+3)  
  21. [bccc]  
  22. [bcccb_x] (+3)  
  23. total cost = 3+3=6  



  24.   
  25. run 2:  
  26. bcb  
  27. bbc  
  28. cbb  
  29. [b]  
  30. [bc_x] (+1)  
  31. [bc_x] (+1)  
  32. [bc_x] (+1)  
  33. [bb]  
  34. [bbb]  
  35. total cost = 1+1+1=3  



  36.   
  37. run 3:  
  38. bcb  
  39. bbc  
  40. cbb  
  41. [b_x] (+3)  
  42. [c]  
  43. [cc]  
  44. [ccb]  
  45. [ccbc]  
  46. [ccbcb_x] (+3)  
  47. total cost = 3+3=6  
  48.   

  49. so min cost 1+1+1=3 (not sure correctness, but you get the idea)  
复制代码
我想问问代码如何写。

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

本版积分规则

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