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

META 电面

全局:

2024(10-12月) 码农类General 硕士 全职@Meta - 内推 - 技术电面  | 😐 Neutral 😐 Average | WaitList | 在职跳槽

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

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

x

人很好的亚洲小哥上来就是两道题


1.163 要输出string
2.没见过 和这道题很像


两个都没刷过都是硬
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
track。估计要没但还是希望别杀我...........

评分

参与人数 5大米 +9 收起 理由
hope2019 + 1 赞一个
匿名用户-GXPYR + 5 欢迎分享你知道的情况,会给更多大米奖励!
iamthomas + 1 给你点个赞!
dannyf + 1 赞一个
418Teapot + 1 给你点个赞!

查看全部评分


上一篇:intern OA 近期做过的百特电丝和提克托克OA合集整理
下一篇:E5 infra 店面 求加大米
地里匿名用户
推荐
匿名用户-LUE4I  2024-11-3 03:31:22
我是一个来自中国大湾区的大哥,也是两道变种(哭了,为啥就我不是原题),是做出来了但也是提醒,加自我感觉不是bug free prefect

求求让过吧,大哥我给你积福
回复

使用道具 举报

推荐
 楼主| Ezhao1995 2024-11-3 14:21:15 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
回复

使用道具 举报

推荐
 楼主| Ezhao1995 2024-11-3 13:38:34 | 只看该作者
全局:
匿名用户 发表于 2024-11-2 22:14
电面这么多code也太难顶了把。。

这么长主要这题我没见过问问题加讨论就已经十分钟了最后我也就有时间写一半。
回复

使用道具 举报

全局:
店面这么复杂的题
回复

使用道具 举报

🔗
Falldawn 2024-11-3 10:58:32 | 只看该作者
全局:
本帖最后由 Falldawn 于 2024-11-2 19:59 编辑

链接里写得看起来太难受了,  ChatGPT的结果,显然不需要再遍历输入了,直接  DFS
  1. class Solution {
  2.     private TrieNode root = new TrieNode();

  3.     // Function to insert a word into the trie
  4.     public void insert(String word) {
  5.         TrieNode node = root;
  6.         for (char ch : word.toCharArray()) {
  7.             node.children.putIfAbsent(ch, new TrieNode());
  8.             node = node.children.get(ch);
  9.             node.count++;
  10.         }
  11.     }

  12.     // Function to find the shortest unique prefix for a word
  13.     public String findPrefix(String word) {
  14.         TrieNode node = root;
  15.         StringBuilder prefix = new StringBuilder();
  16.         for (char ch : word.toCharArray()) {
  17.             prefix.append(ch);
  18.             node = node.children.get(ch);
  19.             if (node.count == 1) {
  20.                 return prefix.toString();
  21.             }
  22.         }
  23.         return word; // if no unique prefix, return the word itself
  24.     }

  25.     // Main function to find all shortest unique prefixes for a list of words
  26.     public List<String> shortestUniquePrefixes(String[] words) {
  27.         for (String word : words) {
  28.             insert(word); // Insert each word into the trie
  29.         }

  30.         List<String> result = new ArrayList<>();
  31.         for (String word : words) {
  32.             result.add(findPrefix(word)); // Find and add the unique prefix
  33.         }
  34.         return result;
  35.     }
  36. }

  37. class TrieNode {
  38.     Map<Character, TrieNode> children = new HashMap<>();
  39.     int count; // count occurrences of words passing through this node
  40. }
复制代码
  1. class Solution {
  2.     private TrieNode root = new TrieNode();

  3.     // Function to insert a word into the trie
  4.     public void insert(String word) {
  5.         TrieNode node = root;
  6.         for (char ch : word.toCharArray()) {
  7.             node.children.putIfAbsent(ch, new TrieNode());
  8.             node = node.children.get(ch);
  9.             node.count++;
  10.         }
  11.     }

  12.     // Function to find the shortest unique prefix for a word
  13.     public String findPrefix(String word) {
  14.         TrieNode node = root;
  15.         StringBuilder prefix = new StringBuilder();
  16.         for (char ch : word.toCharArray()) {
  17.             prefix.append(ch);
  18.             node = node.children.get(ch);
  19.             if (node.count == 1) {
  20.                 return prefix.toString();
  21.             }
  22.         }
  23.         return word; // if no unique prefix, return the word itself
  24.     }

  25.     public void findUniquePrefixes(TrieNode node, StringBuilder prefix, List<String> result) {
  26.         if (node == null) return;
  27.         
  28.         // If this node is end of a word and count is 1, it's a unique prefix
  29.         if (node.count == 1) {
  30.             result.add(prefix.toString());
  31.             return;
  32.         }
  33.         
  34.         // Recur for all children
  35.         for (Map.Entry<Character, TrieNode> entry : node.children.entrySet()) {
  36.             prefix.append(entry.getKey());
  37.             findUniquePrefixes(entry.getValue(), prefix, result);
  38.             prefix.deleteCharAt(prefix.length() - 1); // Backtrack
  39.         }
  40.     }
  41.     // Main function to find all shortest unique prefixes for a list of words
  42.     public List<String> shortestUniquePrefixes(String[] words) {
  43.         for (String word : words) {
  44.             insert(word); // Insert each word into the trie
  45.         }

  46.         List<String> result = new ArrayList<>();
  47.         StringBuilder sb = new StringBuilder();
  48.         findUniquePrefixes(root, sb, result);
  49.         return result;
  50.     }
  51. }

  52. class TrieNode {
  53.     Map<Character, TrieNode> children = new HashMap<>();
  54.     int count; // count occurrences of words passing through this node
  55. }
复制代码
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-NMAVM  2024-11-3 12:14:35
Falldawn 发表于 2024-11-2 19:58
链接里写得看起来太难受了,  ChatGPT的结果,显然不需要再遍历输入了,直接  DFS

电面这么多code也太难顶了把。。
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-NMAVM  2024-11-3 12:33:37
想问一下楼主第一题要输出string是什么意思?
回复

使用道具 举报

🔗
 楼主| Ezhao1995 2024-11-3 13:37:33 | 只看该作者
全局:
Falldawn 发表于 2024-11-2 20:58
链接里写得看起来太难受了,  ChatGPT的结果,显然不需要再遍历输入了,直接  DFS

这么长主要这题我没见过问问题加讨论就已经十分钟了最后我也就有时间写一半。
回复

使用道具 举报

全局:
Ezhao1995 发表于 2024-11-02 22:38:34
这么长主要这题我没见过问问题加讨论就已经十分钟了最后我也就有时间写一半。
是不是可以sort一下然后只比较相邻的,
回复

使用道具 举报

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

本版积分规则

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