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

pinterest 电面跪经

全局:

2017(10-12月) 码农类General 本科 全职@pinterest - 内推 - 技术电面  | | Fail | 在职跳槽

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

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

x
跪的略奇妙,可能还是简历不好看。面试官花了半个小时的时间聊天,然后明确说了只面一道。
给一个很大的字典(有问面试官需不需要
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
有再问别的followup。

回头也在自己电脑上跑了,没什么问题。然而还是跪了


上一篇:Google OA
下一篇:巴克莱 面经 intern 2018
推荐
 楼主| sunyanzi 2017-11-17 06:26:18 | 只看该作者
全局:
LeeYYY 发表于 2017-11-15 15:37
这题就是 LC原题:

https://leetcode.com/problems/longest-word-in-dictionary/description/

感觉就是从我这个帖子过去的。。。
回复

使用道具 举报

推荐
wobujupa 2017-10-31 00:45:58 | 只看该作者
全局:
  1. public class BuildDict {

  2.     public static TrieNode root;

  3.     public static void main(String[]args){
  4.         String[] dict = {"w", "wo", "wor", "wt", "world", "worl", "wto"};
  5.         System.out.println(maxWord(dict));
  6.     }

  7.     public static String maxWord(String[] dict){
  8.         int max = 0;
  9.         String res = "";
  10.         root = new TrieNode(0, "");
  11.         for(String word : dict){
  12.             TrieNode node = root;
  13.             char[] arr = word.toCharArray();
  14.             for(char c : arr){
  15.                 if(node.children[c - 'a'] == null){
  16.                     node.children[c - 'a'] = new TrieNode(node.depth + 1, node.word + c);
  17.                 }
  18.                 node = node.children[c - 'a'];
  19.             }
  20.             if(node.depth > max){
  21.                 max = node.depth;
  22.                 res = node.word;
  23.             }
  24.         }
  25.         return res;
  26.     }

  27. }

  28. class TrieNode{
  29.     TrieNode[] children;
  30.     int depth;
  31.     String word;

  32.     public TrieNode(int d, String w){
  33.         depth = d;
  34.         children = new TrieNode[26];
  35.         word = w;
  36.     }
  37. }
复制代码


按照楼主的意思,写了一版代码,能不能麻烦看下是不是这个意思,谢谢
回复

使用道具 举报

推荐
wobujupa 2017-10-31 01:38:28 | 只看该作者
全局:
  1. public class BuildDict {

  2.     public static TrieNode root;

  3.     public static void main(String[]args){
  4.         String[] dict = {"world", "wo", "wt", "wor", "w", "worl", "wto"};
  5.         System.out.println(maxWord(dict));
  6.     }


  7.     public static String maxWord(String[] dict){
  8.         if(dict == null || dict.length == 0) return "";
  9.         Map<String, Integer> map = new HashMap<>();
  10.         Queue<String> queue = new LinkedList<>();
  11.         for(String word : dict){
  12.             if(word.length() == 1) {
  13.                 queue.add(word);
  14.             }
  15.             map.put(word, 0);
  16.         }
  17.         String res = "";
  18.         while(!queue.isEmpty()){
  19.             int size = queue.size();
  20.             for(int i = 0; i < size; i++){
  21.                 String word = queue.poll();
  22.                 for(char c = 'a'; c <= 'z'; c++){
  23.                     String tmpWord = word + c;
  24.                     if(map.containsKey(tmpWord)){
  25.                         queue.add(tmpWord);
  26.                         res = tmpWord;
  27.                     }
  28.                 }
  29.             }
  30.         }
  31.         return res;
  32.     }
  33. }
复制代码


重新写了一版,感觉不用trie也好,用bfs,从1个字符的word开始,有点点像word ladder,楼主提到如果有多个同样长度的话,返回随便一个就好的话,不断更新的话,最后queue空的时候,最后更新的值就是最大长度的word了。还请各位大神指教
回复

使用道具 举报

🔗
wtcupup 2017-10-16 15:09:48 | 只看该作者
全局:
输出是list of strings ?
回复

使用道具 举报

🔗
 楼主| sunyanzi 2017-10-17 07:47:39 | 只看该作者
全局:
输出就是那个最长的词,有问面试官,如果有同样长度的很多词,要全输出吗,面试官说不用,只用输出一个。
回复

使用道具 举报

🔗
randrand1 2017-10-17 07:57:34 | 只看该作者
全局:
这个build的过程总是从最后添加charactor吗?可不可以这样a->ba ?
回复

使用道具 举报

🔗
zhuangtuo 2017-10-17 09:01:28 | 只看该作者
全局:
lz去反应一下,
顺便问问反馈,哪里要改进.
回复

使用道具 举报

🔗
 楼主| sunyanzi 2017-10-17 09:05:56 | 只看该作者
全局:
randrand1 发表于 2017-10-17 07:57
这个build的过程总是从最后添加charactor吗?可不可以这样a->ba ?

不可以, 原话是build the string one character at a time
回复

使用道具 举报

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

使用道具 举报

🔗
vae371 2017-10-17 09:51:40 | 只看该作者
全局:
好吧,这为什么没过?是现在都要求这么高还是缘分没到
回复

使用道具 举报

🔗
烩丸子 2017-10-20 10:43:47 | 只看该作者
全局:
有点不太懂题意,楼主可以解释一下吗?每个字母只能用一次吗?
回复

使用道具 举报

🔗
 楼主| sunyanzi 2017-10-21 12:57:09 | 只看该作者
全局:
烩丸子 发表于 2017-10-20 10:43
有点不太懂题意,楼主可以解释一下吗?每个字母只能用一次吗?

不知道要怎么样才可以讲的更清楚,就是如果字典里有a, ab, abc,那么你就可以输出abc这个词
回复

使用道具 举报

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

本版积分规则

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