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

一月三十一号狗家昂赛

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

使用道具 举报

全局:
第一题

  1.     public int minForReg(String reg, int s, int e){
  2.         int cnt = 0;
  3.         int min = Integer.MAX_VALUE;
  4.         for(int i = s; i<=e; i++){
  5.             char c = reg.charAt(i);
  6.             if(c=='X'){
  7.                 cnt++;
  8.             }else if(c=='|'){
  9.                 min = Math.min(cnt, min);
  10.                 cnt  = 0;
  11.             }else if(c=='('){
  12.                 int end = i+1;
  13.                 int left = 1;
  14.                 while(end<=e && (reg.charAt(end)!=')' || left!=1)){
  15.                     if(reg.charAt(end)=='(') left++;
  16.                     if(reg.charAt(end)==')') left--;
  17.                     end++;
  18.                 }
  19.                 cnt+=minForReg(reg, i+1, end-1);//不用包含括号了!
  20.                 i=end;
  21.             }
  22.         }
  23.         if(cnt!=0) min = Math.min(cnt, min);
  24.         return min;
  25.     }
复制代码


O(n)吧
回复

使用道具 举报

🔗
feyhi 2017-2-21 15:14:24 | 只看该作者
全局:
第五题Tree+Iterator有点微妙,至少children也要是用iterator来access。不然给你一个有巨多个<li>的页面就挂了。同理text也要考虑要不要用iterator。
无论如何还得有个很神的parsing算法来构造这个Tree+Iterator结构。
回复

使用道具 举报

🔗
bigbearlake 2017-3-7 17:07:47 | 只看该作者
全局:
consciousgaze 发表于 2017-2-3 05:03
发几遍格式都不对……直接贴raw text了
一轮题二:
这道题只是写了dfs里while里的框架,解释思路面试官看 ...

这个有问题吧,比如 121314...这种,如果是按照12来解,一下略过了12个字符就不对吧,因为其实只能是1个21个三
回复

使用道具 举报

🔗
bigbearlake 2017-3-8 00:53:09 | 只看该作者
全局:
consciousgaze 发表于 2017-2-3 05:03
发几遍格式都不对……直接贴raw text了
一轮题二:
这道题只是写了dfs里while里的框架,解释思路面试官看 ...

应该是 count + 1 + int(c);
回复

使用道具 举报

🔗
bigbearlake 2017-3-8 01:46:47 | 只看该作者
全局:
consciousgaze 发表于 2017-2-3 05:04
第三轮:
这道题面筋里有,不过我没看到完整清楚的解法,这次写了就写一下吧
给出string s,和dict d。求 ...

请问用trie怎么做呢,把words存到trie里?
回复

使用道具 举报

🔗
bigbearlake 2017-3-8 14:29:00 | 只看该作者
全局:
第三轮,java version
  1. public class LongestSubsequenceInDict {

  2.     public String longestSubsequenceWord(String s, Set<String> dict) {
  3.         String res = "";
  4.         for (String word : dict) {
  5.             if (word.length() > res.length() && isSebsequence(s, word)) {
  6.                 res = word;
  7.             }
  8.         }

  9.         return res;
  10.     }

  11.     private boolean isSebsequence(String s, String word) {
  12.         int i = 0;
  13.         int j = 0;
  14.         while (i < s.length() && j < word.length()) {
  15.             if (s.charAt(i) == word.charAt(j)) {
  16.                 i++;
  17.                 j++;
  18.             } else {
  19.                 i++;
  20.             }
  21.         }

  22.         return j == word.length();
  23.     }


  24.     public String longestSubsequenceWord1(String s, Set<String> dict) {
  25.         String res = "";
  26.         HashMap<Character, TreeSet<Integer>> cachedS = buildCachedS(s);
  27.         
  28.         for (String word : dict) {
  29.             if (word.length() > res.length() && isSebsequence1(cachedS, word)) {
  30.                 res = word;
  31.             }
  32.         }

  33.         return res;
  34.     }

  35.     private HashMap<Character,TreeSet<Integer>> buildCachedS(String s) {
  36.         HashMap<Character,TreeSet<Integer>> map = new HashMap<>();
  37.         for (int i = 0; i < s.length(); i++) {
  38.             char c = s.charAt(i);
  39.             if (map.containsKey(c)) {
  40.                 map.get(c).add(i);
  41.             } else {
  42.                 map.put(c, new TreeSet<>());
  43.                 map.get(c).add(i);
  44.             }
  45.         }

  46.         return map;
  47.     }

  48.     private boolean isSebsequence1(HashMap<Character, TreeSet<Integer>> map, String word) {
  49.         int pos = 0;
  50.         int i = 0;
  51.         for (; i < word.length(); i++) {
  52.             char c = word.charAt(i);
  53.             if (!map.containsKey(c) || map.get(c).ceiling(pos) == null) {
  54.                 return false;
  55.             }
  56.             pos = map.get(c).ceiling(pos);

  57.         }
  58.         return i == word.length();
  59.     }



  60.     public static void main(String[] args) {
  61.         LongestSubsequenceInDict l = new LongestSubsequenceInDict();
  62.         HashSet<String> set = new HashSet<>();
  63.         set.add("abc");
  64.         set.add("abbbc");
  65.         set.add("abb");
  66.         System.out.println(l.longestSubsequenceWord1("aaaaaaabbbbbbdddddd", set));
  67.         System.out.println(l.longestSubsequenceWord1("aaaaaaabbbbbbddddddc", set));
  68.     }
  69. }
复制代码
回复

使用道具 举报

🔗
bigbearlake 2017-3-8 15:27:11 | 只看该作者
全局:
consciousgaze 发表于 2017-2-3 10:19
第四轮code

def getFirstInt(byteArray):

请问返回第一个数是指什么?
回复

使用道具 举报

🔗
bigbearlake 2017-3-27 03:43:35 | 只看该作者
全局:
consciousgaze 发表于 2017-2-3 04:59
一轮题一:判断regex可以包含的最少字符。我的解法起码有一个可以不用stack的地方(注释里说了),也应该能 ...

没看懂,这个题是要问什么呢,最少的字符是要满足什么条件?
回复

使用道具 举报

🔗
bigbearlake 2017-3-27 07:31:18 | 只看该作者
全局:
第四轮code
  1. public class ParseVariableLengthInteger {

  2.     public static void main(String[] args) {
  3.         int[] arr = {0b10000101, 0b00100001, 0b11010101};
  4.         System.out.println(isCorrectFormat(arr));
  5.     }

  6.     public static boolean isCorrectFormat(int[] arr) {
  7.         if (arr == null || arr.length == 0) {
  8.             return true;
  9.         }

  10.         int count = 0;
  11.         for (int i = 0; i < arr.length; i++) {
  12.             if (count == 0) {
  13.                 int  v = arr[i];
  14.                 if ((v >> 7) == 1) {
  15.                     count = 0;
  16.                 } else if ((v >> 6) == 0b01) {
  17.                     count = 1;
  18.                 } else if ((v >> 5) == 0b001) {
  19.                     count = 2;
  20.                 } else if ((v >> 4) == 0b0001) {
  21.                     count = 3;
  22.                 } else {
  23.                     return false;
  24.                 }
  25.             } else {
  26.                 count--;
  27.                 if (count < 0) {
  28.                     return false;
  29.                 }
  30.             }
  31.         }

  32.         return count == 0;
  33.     }
  34. }
复制代码
回复

使用道具 举报

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

本版积分规则

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