📣 独立日限时特惠: VIP通行证立减$68
123
返回列表 发新帖
楼主: eejchen
跳转到指定楼层
上一主题 下一主题
收起左侧

狗家挂经

全局:

这样啊,不是说一般match上team,过HC概率会大吗?看来都不一定~~楼主不要灰心,继续加油哈~
回复

使用道具 举报

🔗
mtrsen 2018-10-15 06:28:50 | 只看该作者
全局:
eejchen 发表于 2018-10-13 23:11
team就是说有自己这方和对手一方,跟下面一个同学说的BFS或者DFS找边界差不多,但是问题是他要求怎么样判 ...

那是不是bfs然后看被包围的有多少棋子然后根据包围的棋子数目看是不是差一个就可以kill
回复

使用道具 举报

🔗
 楼主| eejchen 2018-10-15 07:02:01 | 只看该作者
全局:
Junny69 发表于 2018-10-14 16:44
请问楼主什么时候onsite的

10.8号。。。。。
回复

使用道具 举报

🔗
JamesJi 2018-10-16 06:44:12 | 只看该作者
全局:
请问下楼主第三题怎么做的
回复

使用道具 举报

🔗
 楼主| eejchen 2018-10-16 07:27:21 | 只看该作者
全局:
JamesJi 发表于 2018-10-16 06:44
请问下楼主第三题怎么做的

其实我也不知道,我用的两个循环。。。
回复

使用道具 举报

🔗
a_stray 2018-10-16 08:50:55 | 只看该作者
全局:
狗家一轮需要面两道题。lz可能做得有点慢, 所以就一轮面了一道

补充内容 (2018-10-15 19:51):
加油!

评分

参与人数 1大米 +3 收起 理由
eejchen + 3 谢谢鼓励!

查看全部评分

回复

使用道具 举报

🔗
 楼主| eejchen 2018-10-17 00:03:10 | 只看该作者
全局:
a_stray 发表于 2018-10-16 08:50
狗家一轮需要面两道题。lz可能做得有点慢, 所以就一轮面了一道

补充内容 (2018-10-15 19:51):

谢谢鼓励!
回复

使用道具 举报

🔗
DylanZhang 2018-11-2 09:31:58 | 只看该作者
全局:
第三题给一个nlogn的思路,greedy,还得证明,代码量也好多,感觉面试的时候很难都写完啊。
  1. /* return the minimum number of deletion and copy to get target String
  2.          store the index of characters in source into index table
  3.          replace target string with the its charactes's index in source string, and try to find as much as continuous increasing index as possible.
  4.          To achieve that, we want to choose index as small as possible, however, need to be greater than previous char's index;
  5.          1. O(n) process the index table
  6.          2. for each character, O(log n) - binary search to find the smallest index that is greater than previous index, if no such index, assign the smallest index of current character
  7.          3. rebuild answer list O(n)
  8.          total: Time: O(n log n) Space: O(n)
  9.          End case, no such character in source. return empty list
  10.          AZAB -> ZBAZ
  11.          i.e.
  12.          1. get table
  13.          A: 2
  14.          Z: 0, 3
  15.          B: 1
  16.          2. assign index: 2,3,2,1
  17.          3. find how many continuous increasing subArray
  18.                  answer: [2,3],[2],[1]
  19.          */
  20.         public List<List<Integer>> canTransForm(String target, String source){
  21.                 // assume only capital letter in target and source
  22.                 if(target == null || source == null || target.length() == 0 || source.length() == 0){
  23.                         return new ArrayList<>();
  24.                 }
  25.                
  26.                 // init index table
  27.                 Map<Character, List<Integer>> map = new HashMap<>();
  28.                 for(int i = 0; i < source.length(); i++){
  29.                         char c = source.charAt(i);
  30.                         List<Integer> indexes = map.get(c);
  31.                         if(indexes == null){
  32.                                 indexes = new ArrayList<>();
  33.                                 map.put(c, indexes);
  34.                         }
  35.                         indexes.add(i);
  36.                 }
  37.                
  38.                 // init the target index array
  39.                 int[] targetIdx = new int[target.length()];
  40.                
  41.                 for(int i = 0; i < target.length(); i++){
  42.                         List<Integer> indexes = map.get(target.charAt(i));
  43.                         if(indexes == null){
  44.                                 return new ArrayList<>();
  45.                         }else{
  46.                                 // binary search index
  47.                                 targetIdx[i] = find(indexes, i == 0 ? Integer.MAX_VALUE : targetIdx[i - 1]);
  48.                         }
  49.                 }
  50.                
  51.                 // build final result list               
  52.                 return buildList(targetIdx);
  53.         }
  54.        
  55.         // binary search smallest number that larger than i
  56.         private int find(List<Integer> indexes, int i){
  57.                 int l = 0;
  58.                 int r = indexes.size() - 1;
  59.                 while(l < r){
  60.                         int mid = l + (r - l) / 2;
  61.                         if(indexes.get(mid) <= i){
  62.                                 l = mid + 1;
  63.                         }else{
  64.                                 r = mid;
  65.                         }
  66.                 }
  67.                
  68.                 if(indexes.get(l) <= i){
  69.                         return indexes.get(0);
  70.                 }else{
  71.                         return indexes.get(l);
  72.                 }
  73.         }
  74.        
  75.         // build final list by count continuous increasing subArray
  76.         private List<List<Integer>> buildList(int[] targetIdx){
  77.                 List<List<Integer>> res = new ArrayList<>();
  78.                 List<Integer> cur = new ArrayList<>();
  79.                 cur.add(targetIdx[0]);
  80.                 for(int i = 1; i < targetIdx.length; i++){
  81.                         if(targetIdx[i] > targetIdx[i - 1]){
  82.                                 cur.add(targetIdx[i]);
  83.                         }else{
  84.                                 res.add(cur);
  85.                                 cur = new ArrayList<>();
  86.                                 cur.add(targetIdx[i]);
  87.                         }
  88.                 }
  89.                 if(cur.size() != 0){
  90.                         res.add(cur);
  91.                 }
  92.                 return res;
  93.         }
复制代码

评分

参与人数 1大米 +5 收起 理由
eejchen + 5 给你点个赞!

查看全部评分

回复

使用道具 举报

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

本版积分规则

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