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

PoketGem - OA

全局:

2017(4-6月) 码农类General 硕士 全职@ - 网上海投 - 在线笔试  | | Other | 应届毕业生

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

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

x
  1. #include <cassert>
  2. #include <cstring>
  3. #include <iostream>
  4. #include <algorithm>
  5. #include <string>
  6. #include <vector>
  7. using namespace std;

  8. struct TrieNode {
  9.         TrieNode() {
  10.                 memset(next, 0, sizeof(next));
  11.                 isEnd = false;
  12.         }
  13.         TrieNode* next[256];
  14.         bool isEnd;
  15. };

  16. struct Trie {
  17.         Trie() {
  18.                 root = new TrieNode();
  19.         }
  20.         TrieNode* insert(const string& s) {
  21.                 TrieNode* result = root;
  22.                 for (const auto &i : s) {
  23.                         if (!result->next[i - 0]) {
  24.                                 result->next[i - 0] = new TrieNode();
  25.                         }
  26.                         result = result->next[i - 0];
  27.                 }
  28.                 result->isEnd = true;
  29.                 return result;
  30.         }
  31.         void dfs(TrieNode* node, string& s, vector<string>& result, const int x, const int y, const vector<string>& boggle_board, const size_t max_length) {
  32.                 const char ch = boggle_board.at(x).at(y);
  33.                 const int id = ch - 0;
  34.                 if (!node or !node->next[id] or max_length < s.size()) {
  35.                         return;
  36.                 }
  37.                 s.push_back(ch);
  38.                 if (node->next[id]->isEnd) {
  39.                         result.push_back(s);
  40.                         node->isEnd = false;
  41.                 }
  42.                 const int dx[9] = {-1, -1, -1, 0, 0, 0, 1, 1, 1}, dy[9] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
  43.                 const int p = boggle_board.size(), q = boggle_board.front().size();
  44.                 for (int i = 0; i < 9; i++) {
  45.                         int nx = x + dx[i], ny = y + dy[i];
  46.                         if (nx >= 0 and nx < p and ny >= 0 and ny < q) {
  47.                                 dfs(node->next[id], s, result, nx, ny, boggle_board, max_length);
  48.                         }
  49.                 }
  50.                 s.pop_back();
  51.         }
  52.         TrieNode* root;
  53. };

  54. vector<string> find_words(vector<string> boggle_board, vector<string> list) {
  55.         if (boggle_board.empty() or list.empty()) {
  56.                 return {};
  57.         }
  58.         const int p = boggle_board.size(), q = boggle_board.front().size();
  59.         size_t max_length = 0;
  60.         Trie trie;
  61.         for (const auto &i : list) {
  62.                 max_length = max(max_length, i.size());
  63.                 trie.insert(i);
  64.         }
  65.         vector<string> output;
  66.         for (int i = 0; i < p; i++) {
  67.                 for (int j = 0; j < q; j++) {
  68.                         string s;
  69.                         trie.dfs(trie.root, s, output, i, j, boggle_board, max_length);
  70.                 }
  71.         }
  72.         sort(begin(output), end(output));
  73.         return output;
  74. }

  75. int main(void) {
  76.         vector<string> boggle_board, list, result, answer;

  77.         boggle_board = {"BBLL", "UNOO", "NGOM", "ASLE"};
  78.         list = {"BLOG", "BOMB", "GLOSS", "SLOGS", "SNAG", "SNAGS"};
  79.         answer = {"BLOG", "GLOSS", "SLOGS", "SNAG", "SNAGS"};
  80.         result = find_words(boggle_board, list);

  81.         assert(answer == result);

  82.         cout << "\nPassed All\n";
  83.         return 0;
  84. }
复制代码

补充内容 (2017-4-27 18:42):
有这么几个注意点 那个Lytmus Challenge 用的C++ 版本比较低 之前leetcode上能够通过的题目 这上面无法通过 换句话说 你得用很早期的C++来写

补充内容 (2017-4-27 18:42):
TrieNode next size 要设置成为 26 而不是 256 Trie Tree 是26
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
trong>
要用 Windows或者 Mac, Linux 只有网页版 很渣!!!!!!!!!!!!!!!!!!!!!!!!!!

补充内容 (2017-5-1 04:36):
2017-04-27 电面拿到 根据HR的反应 我应该过掉了全部testcase 根据地里面的经验 我一般是拿来充数的。。。。

上一篇:请问有Uber 2017 Summer Intern的群吗
下一篇:最新fb onsite面经
推荐
 楼主| LeetCodeOJ 2017-4-27 18:53:30 | 只看该作者
全局:
  1. Feedback

  2. Your answer successfully passed all basic test cases. This does not guarantee that your answer is completely correct.

  3. The following basic test cases were run on your answer:

  4. Description: Compile candidate language
  5. Score: 100 out of 100
  6. Your answer successfully compiled

  7. Description: Testing that words can be found on board with basic Boggle rules
  8. Score: 100 out of 100
  9. When the input is
  10. list_path=/home/candidate/author_files/tests/try_answer/inputs/Simple_Test_01.txt, boggle_board=['hel', 'owo', 'rld']
  11. your program correctly outputs
  12. ['hello', 'world']

  13. Description: Testing against the boggle board provided in the question statement
  14. Score: 100 out of 100
  15. When the input is
  16. list_path=/home/candidate/author_files/tests/try_answer/inputs/Question_Statement_Example_02.txt, boggle_board=['bbll', 'unoo', 'ngom', 'asle']
  17. your program correctly outputs
  18. ['aa', 'aga', 'agag', 'aglossa', 'ago', 'agog', 'agon', 'an', 'ana', 'anan', 'anana', 'ananas', 'anas', 'anasa', 'angle', 'ango', 'ann', 'anna', 'ansa', 'as', 'asa', 'asana', 'blo', 'blob', 'bloom', 'bo', 'bob', 'bobo', 'bog', 'boga', 'bogan', 'boggle', 'bogle', 'bogo', 'bogong', 'boll', 'bolo', 'bologna', 'bolognan', 'bom', 'bon', 'bonbo', 'bonbon', 'bong', 'bongo', 'boo', 'boob', 'bool', 'boom', 'boon', 'bu', 'bub', 'bubo', 'bug', 'bugan', 'bugle', 'bugloss', 'bun', 'buna', 'bung', 'bunga', 'bungle', 'bungo', 'eel', 'el', 'ell', 'elle', 'elm', 'elon', 'els', 'elsa', 'em', 'eme', 'emm', 'eon', 'ga', 'gag', 'gaggle', 'gan', 'gang', 'ganga', 'gangan', 'ganggang', 'gas', 'gasan', 'glee', 'glom', 'glome', 'gloom', 'gloss', 'glossa', 'gnome', 'gnomon', 'gnu', 'go', 'gob', 'gobo', 'goel', 'gog', 'gogga', 'goggan', 'goggle', 'gogo', 'gol', 'golee', 'golem', 'goll', 'golo', 'goloe', 'gon', 'gong', 'gonosome', 'goo', 'googol', 'gool', 'gools', 'goon', 'gos', 'gossan', 'gossoon', 'gubbo', 'guggle', 'gugu', 'gun', 'guna', 'gunl', 'gunnung', 'gunong', 'lee', 'lemel', 'lemon', 'leo', 'leon', 'lo', 'lob', 'lobo', 'log', 'logos', 'loll', 'lolo', 'long', 'longa', 'longan', 'longs', 'longsome', 'loo', 'loom', 'loon', 'loss', 'me', 'mel', 'mele', 'melee', 'mell', 'mellon', 'meloe', 'melon', 'melos', 'melosa', 'mem', 'memo', 'meo', 'mo', 'mob', 'moe', 'moellon', 'mog', 'moggan', 'mogo', 'mogollon', 'mole', 'moll', 'molle', 'mome', 'momme', 'momo', 'mon', 'mong', 'mongo', 'mongol', 'mono', 'mon... (Output truncated)
复制代码
回复

使用道具 举报

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

使用道具 举报

推荐
 楼主| LeetCodeOJ 2017-4-27 18:52:52 | 只看该作者
全局:
  1. Boggle with a Twist!

  2. For this question, you will write a solver for the game Boggle, with a twist. The game of Boggle is played on a N-by-N grid of letters. For example, the following is possible board:

  3. B        B        L        L
  4. U        N        O        O
  5. N        G        O        M
  6. A        S        L        E

  7. A player tries to find as many English words as possible by traversing the grid one step at a time, horizontally, vertically and diagonally. For example BLOG is a valid word as is SNAG.

  8. In this variation of the game, you are allowed to use a letter in a given position more than once. Your path can continue from any letter to any other connected letter, including itself. For example, SNAGS, SLOGS and GLOSS are all valid words. Note that the repeated letters must still be in the path of the grid traversal, so the word BOMB is not allowed.

  9. Complete the function find_words. The first input is a list of strings (boggle_board), where each string represents a row on the board; the largest board we will give as an input is a 4-by-4. The second is a string path (list_path), which points to a .txt file. This file contains a list of words sorted in alphabetical order, with no duplicates. All words are at least 2 letters in length. An example list has been provided for you in the inputs directory.

  10. Your completed function is to return a list of all the words, in lowercase, from the .txt file that can be constructed from the given boggle board. The list should be sorted alphabetically and contain no duplicates. Your function should not need to modify the .txt file.
复制代码
回复

使用道具 举报

🔗
 楼主| LeetCodeOJ 2017-4-27 18:45:18 | 只看该作者
全局:
std::vector<std::string> find_words(std::vector<std::string> boggle_board, std::string list_path)这个是对的!!!
回复

使用道具 举报

🔗
 楼主| LeetCodeOJ 2017-4-27 18:50:16 | 只看该作者
全局:
照抄我的代码有风险 非常非常建议自己亲自做一下LeetCode 212. Word Search II 算法完全一样 只有一个地方不同 代码 44 和 46 行
回复

使用道具 举报

🔗
 楼主| LeetCodeOJ 2017-4-27 18:54:21 | 只看该作者
全局:
注意看我下面的回复!!!!!

补充内容 (2017-4-27 18:54):
上面。。。。
回复

使用道具 举报

🔗
rcholic 2017-5-1 04:28:49 | 只看该作者
全局:
我刚刚提交了这个oa,然后上网一搜就找到这个帖子了!
一模一样的题目,不过我是用java写的

祝我们好运!
回复

使用道具 举报

🔗
rcholic 2017-5-1 04:30:11 | 只看该作者
全局:
我在take 这个oa之前还是按去年的面经准备的all paths from A to E呢,还有那个log parser的问题。。。
要是考前再搜一下,很可能是考oa之前就找到这个最新面经了!!!
回复

使用道具 举报

🔗
 楼主| LeetCodeOJ 2017-5-1 04:31:59 | 只看该作者
全局:
rcholic 发表于 2017-5-1 04:28
我刚刚提交了这个oa,然后上网一搜就找到这个帖子了!
一模一样的题目,不过我是用java写的

LOL 不要怕!积累人品
回复

使用道具 举报

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

本版积分规则

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