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

FaceBook Onsite

全局:

2014(7-9月) 码农类General 硕士 全职@meta - 内推 - Onsite  | | Other |

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

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

x
跑去脸谱家面试。搜集不少题目现在列下
1:print all path
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies

还有一些简单题估计人家随便找的,祝好运。

评分

参与人数 6大米 +99 收起 理由
JamesGTI + 3 感谢分享!
jby1797 + 10
xz28us + 20
xixi_second + 3 感谢分享!
haoshenxiong + 3 感谢分享!

查看全部评分


上一篇:epic 电面 总结
下一篇:LiveRamp热呼呼
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
回复

使用道具 举报

全局:
palindrome pair, 贴一个我写的很撮的程序:
抛砖引玉:求指点。
  1. import java.util.HashMap;
  2. import java.util.List;
  3. import java.util.ArrayList;
  4. import java.util.Map;
  5. import java.util.Iterator;
  6. import java.util.Set;
  7. import java.util.HashSet;

  8. public class PalindromePairs {
  9.         public static List<String> palinPair(String[] arr) {
  10.                 List<String> palin = new ArrayList<String>();
  11.                 if(arr == null || arr.length == 1)        return palin;
  12.                 TreeNodeInTrie root = buildTree(arr);                               
  13.                 for(String s : arr) {
  14.                         String rev = (new StringBuffer(s)).reverse().toString();
  15.                         TreeNodeInTrie curr = root;
  16.                         StringBuffer sb = new StringBuffer();
  17.                         int i = 0;
  18.                         boolean cont = true;
  19.                         Set<String> finished = new HashSet<String>();
  20.                         finished.add(s);
  21.                         for(; i < rev.length(); ++i) {
  22.                                 if(curr.isWord && isPalindrome(s, i, rev.length() - 1)) {
  23.                                         if(finished.add(sb.toString()))
  24.                                                 palin.add(sb.toString() + ":"+s);
  25.                                 }
  26.                                
  27.                                 if(curr.child != null && curr.child.containsKey(rev.charAt(i))) {
  28.                                         curr = curr.child.get(rev.charAt(i));
  29.                                         sb.append(rev.charAt(i));
  30.                                 }else{
  31.                                         cont = false;
  32.                                         break;
  33.                                 }
  34.                         }
  35.                         if(cont) {
  36.                                 if(i < rev.length()){ //curr is a leaf of the trie tree
  37.                                         if(isPalindrome(rev, i, rev.length() - 1)) {
  38.                                                 if(finished.add(sb.toString()))
  39.                                                         palin.add(sb.toString() + ":"+s);
  40.                                         }
  41.                                 }else{ //curr is not a leaf of the trie tree
  42.                                         if(curr.isWord) {
  43.                                                 if(finished.add(sb.toString()))
  44.                                                         palin.add(sb.toString() + ":"+s);
  45.                                         }                                       
  46.                                         if(curr.child != null){
  47.                                                 List<String> rem = new ArrayList<String>();
  48.                                                 dfs(curr, rem, new StringBuffer());
  49.                                                 for(String s1: rem) {
  50.                                                         if(isPalindrome(s1,0, s1.length() - 1)) {
  51.                                                                 if(finished.add(sb.toString() + s1))
  52.                                                                         palin.add(sb.toString()+s1+":"+ s);
  53.                                                         }
  54.                                                 }
  55.                                         }       
  56.                                 }
  57.                         }
  58.                 }
  59.                
  60.                 return palin;
  61.         }
  62.        
  63.         private static void dfs(TreeNodeInTrie curr, List<String> rem, StringBuffer sb){
  64.                 if(curr.child == null) {                       
  65.                         return;
  66.                 }               
  67.                 Iterator<Character> its = curr.child.keySet().iterator();
  68.                 while(its.hasNext()){
  69.                         char ch= its.next();
  70.                         sb.append(ch);
  71.                         if(curr.child.get(ch).isWord)         rem.add(new String(sb));
  72.                         dfs(curr.child.get(ch), rem, sb);                       
  73.                         sb.deleteCharAt(sb.length() - 1);
  74.                 }               
  75.         }
  76.        
  77.        
  78.         private static boolean isPalindrome(String s, int i, int j) {
  79.                 if(i >= j)        return true;
  80.                 while(i < j) {
  81.                         if(s.charAt(i) != s.charAt(j))                return false;
  82.                         ++i;
  83.                         --j;
  84.                 }
  85.                 return true;
  86.         }
  87.        
  88.         private static TreeNodeInTrie buildTree(String[] arr){
  89.                 TreeNodeInTrie root = new TreeNodeInTrie(' ', false);
  90.                 for(String s : arr) {
  91.                         int len = s.length();
  92.                         TreeNodeInTrie curr = root;
  93.                         for(int i = 0; i < len; ++i) {
  94.                                 if(curr.child == null){         //child is empty, create child and a new TreeNodeInTrie
  95.                                         Map<Character, TreeNodeInTrie> child = new HashMap<Character, TreeNodeInTrie>();                                       
  96.                                         curr.child = child;
  97.                                 }
  98.                                
  99.                                 if(curr.child.containsKey(s.charAt(i))) {        //if the TreeNodeInTrie exists;
  100.                                         if(i == len - 1)                curr.child.get(s.charAt(i)).isWord = true;
  101.                                 }else{                 //if the TreeNodeInTrie does not exists
  102.                                         curr.child.put(s.charAt(i), new TreeNodeInTrie(s.charAt(i), i == len - 1));
  103.                                 }                       
  104.                                 curr = curr.child.get(s.charAt(i));          // recursively
  105.                         }
  106.                 }
  107.                 return root;
  108.         }
  109.        
  110.        
  111.         public static void main(String[] args) {
  112.                 String[] arr = new String[] {"a", "aa", "aaa"};
  113.                 System.out.println(palinPair(arr));
  114.                 String[] arr1 = new String[] {"shit", "tihsa"};
  115.                 System.out.println(palinPair(arr1));
  116.         }
  117. }
  118. class TreeNodeInTrie {
  119.         char c;
  120.         Map<Character, TreeNodeInTrie> child;
  121.         boolean isWord;
  122.         TreeNodeInTrie(char c, boolean isWord){
  123.                 this.c = c;
  124.                 this.isWord = isWord;
  125.         }
  126. }
复制代码

补充内容 (2014-11-6 03:28):
给的两个例子跑出来的结果是:
[aa:a, aaa:a, a:aa, aaa:aa, a:aaa, aa:aaa]
[tihsa:shit]
回复

使用道具 举报

推荐
jason51122 2014-10-23 10:53:55 | 只看该作者
全局:
楼主能麻烦解释下什么是palindrome pairs吗 谢谢了

点评

这个东西,,你完全可以自己google的啊。。。  发表于 2014-11-5 09:11
回复

使用道具 举报

🔗
shinichish 2014-10-13 00:42:15 | 只看该作者
全局:
第二题是快速幂吗?第四题实现啥?
回复

使用道具 举报

🔗
 楼主| 菡萏之默 2014-10-13 00:57:24 | 只看该作者
全局:
不知道为啥写不上,implement BufferedReader
回复

使用道具 举报

🔗
北美农民 2014-10-13 01:03:11 | 只看该作者
全局:
菡萏之默 发表于 2014-10-12 11:57
不知道为啥写不上,implement BufferedReader

要实现啥功能? 这个bufferedreader.
回复

使用道具 举报

🔗
haoshenxiong 2014-10-13 03:35:29 | 只看该作者
全局:
请问没有设计题吗lz?
回复

使用道具 举报

🔗
shinichish 2014-10-13 06:36:55 | 只看该作者
全局:
菡萏之默 发表于 2014-10-13 00:57
不知道为啥写不上,implement BufferedReader

BufferedReader。。。?我Google下
回复

使用道具 举报

🔗
linuxcoder 2014-10-13 10:23:22 | 只看该作者
全局:
问一下楼主一共几轮呀
回复

使用道具 举报

🔗
lhh_NJU 2014-10-13 14:10:02 | 只看该作者
全局:
问一下楼主第三题是需要用Trie吗?
回复

使用道具 举报

🔗
lhh_NJU 2014-10-13 14:10:37 | 只看该作者
全局:
北美农民 发表于 2014-10-13 01:03
要实现啥功能? 这个bufferedreader.

同关注这个BufferedReader
回复

使用道具 举报

🔗
littlecoolblaxk 2014-10-13 14:18:34 | 只看该作者
全局:
lhh_NJU 发表于 2014-10-13 14:10
问一下楼主第三题是需要用Trie吗?

第三题应该是经典的anagrams吧 cc150好像有 lc上一定有 常规解法是用hashmap来做
回复

使用道具 举报

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

本版积分规则

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