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

狗家onsite面经

 
地里匿名用户
🔗
匿名用户-8ADBH  2021-4-9 08:22:38
感谢楼主 T T 这几题真的太硬核了
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-L5ZEC  2021-4-9 13:35:05
本帖最后由 匿名 于 2021-4-9 13:39 编辑
匿名者 发表于 2021-4-7 23:49
请问线段那题有什么技巧吗

可以用TreeSet做, 内部存一个线段
回复

使用道具 举报

🔗
hjldtc 2021-4-12 04:10:34 | 只看该作者
全局:
分享一个简单的encode的办法replace(#,##) 用_#_来当delimiter 这样原本的_#_变成了_##_ 不会和delimiter冲突 split的时候就用_#_ 还原的时候replace(##,#)

评分

参与人数 1大米 +1 收起 理由
侵权 + 1 欢迎分享你知道的情况,会给更多积分奖励!

查看全部评分

回复

使用道具 举报

地里匿名用户
🔗
匿名用户-L5ZEC  2021-4-12 14:11:30
hjldtc 发表于 2021-4-12 04:10
分享一个简单的encode的办法replace(#,##) 用_#_来当delimiter 这样原本的_#_变成了_##_ 不会和delimiter冲 ...

点赞, 有道理. 这题还有几个Corner case需要注意一下, node.val = null, node.val = "" 还有node = null 这三个得能区分出来
回复

使用道具 举报

🔗
bigboss789 2021-4-13 23:18:31 | 只看该作者
全局:
匿名者 发表于 2021-4-8 12:45
是的Trie 存字典, 然后dfs下去, 和 word 一起算dp, 因为下一层dp只和上一层dp有关, 所以可以传一个dp arr ...

我的基本思路就是用“\” 做escape。 你说的转义符,是不是就是找一些不需要escape的sign, 用这些sign加escape去表示这几个特殊的?
比如 :
“” -> \s
value null -> \n

大概这样
回复

使用道具 举报

🔗
zanbin2046 2021-4-15 06:03:12 | 只看该作者
全局:
本帖最后由 zanbin2046 于 2021-4-15 06:08 编辑

p1
  1. def kclose(lst, wd, k):
  2. #build dict
  3. dit = collections.defaultdict(set)
  4. for w in last:
  5.    for i in range(len(w)):
      
  6.       k = w[0:i]+’*’+w[i+1:]
  7.       dit[k].add(w)

  8. stk = [wd]
  9. res = set()
  10. res.add(wd)
  11. while stk and k:
  12.         k -=1
  13.         l = len(stk)
  14.         for i in range(l):
            
  15.             p = stk.pop(0)
  16.              # find all one hop neighbors     
  17.             for j in range(len(p)):
               
  18.                t= w[0:j]+’*’+w[j+1:]
  19.                for w in dit[t]:
  20.                   if w not in res:                                                stk.append(w)
  21.                     res.add(w)      
  22.                   
  23. return list(res)
复制代码






回复

使用道具 举报

全局:
麻烦问一下楼主,第一题里的edit distance是什么意思,只能修改字符吗 还是说增删改都可以。所以的单词长度都是一样的吗
回复

使用道具 举报

🔗
armu 2021-4-25 23:12:36 | 只看该作者
全局:
Gligfdyjfrtfds 发表于 2021-4-24 01:33
麻烦问一下楼主,第一题里的edit distance是什么意思,只能修改字符吗 还是说增删改都可以。所以的单词长度 ...

估计就是leetcode上的编辑距离那道题吧。。。
回复

使用道具 举报

🔗
幺二三 2021-5-2 04:24:02 | 只看该作者
全局:
楼主这些题有点吓人啊
回复

使用道具 举报

🔗
yyyyyz 2021-5-8 02:56:25 | 只看该作者
全局:
是真的难。。。



1. Design一个 auto spell-correction: 讨论下来, 面试官想给我一个Collection<String> dictionary 表示字典, 让我设计一个数据结构, 实现一个API :  List<String> findKClosest(String word, int k) : 返回字典里所有的距离 word 的 edit distance <= k 的单词, 单词按照edit distance排序, 如果edit distance相同, 按照alphabetical排序
可以Trie + DFS + DP + TreeSet 实现  
priority_queue<pair<int,string>, vector<pair<int,string>>, greater<pair<int,string>>> pq = {};
vector<string> findKClosest(string word, int k, vector<string> words){
        TrieNode* root;
        for(string s:words)
                insert(root,s);

        TrieNode* p = root;
        dfs(word,0,p,0,k);

        vector<string> res = {};
        while(!pq.empty()){
                res.push_back(pq.top().second);
                pq.pop();
        }
        return res;
}

void dfs(string word, int idx, Trie* p, int ED, int k){
        if(idx == word.size()){
                pq.push({ED,word});
                return;
        }

        // not change
        if(p->next[word[idx]-'a'])
                dfs(word,idx+1,p->next[word[idx]-'a'],ED,k);

        // if change
        string tmp = word;
        for(int i=0; i<26; ++i){
                if(p->next[i] && word[idx]!= (char)('a'+i) && ED+1<=k){
                        tmp[idx] = (char)('a'+i);
                        dfs(tmp,idx+1,p->next[tmp[idx]],ED+1,k);
                        tmp = word;
                }
        }

}


2. LC 57 + LC 1272 推广: design 一个数据结构, 支持三个api: add(int start, int end), remove(int start, int end), isExist(int start, int end):  能往这个数据结构里add 线段, remove 线段, 可以query某个线段是不是被现在数据结构里include 比如: add(1, 3)  add (2, 5)  add(7, 9) add(15, 20) 这时候内部有这样的线段 [1, 5] [7, 9] [15, 20], isExist(2,3): true  isExist(4, 6) false. 如果remove(4, 8) 内部的线段 [1,3] [9, 9] [15, 20]
        715

3. Serialize/Deserialize Binary Tree: 但是面试官说 TreeNode 的 field是String, 可以是任意String. 我本来想用"," 间隔, 但面试官说val就可以是逗号, 并且可以任意Unicode组成的String, 任何我想拿来当分隔符的符号, 都可以是val

TreeNode {
     String val;
     TreeNode left, right;
}  
我想到的可以用转义符解决, "," 表示逗号  "\," 表示分隔符,   "\\" 才表示 \

class Codec {
public:
    string serialize(TreeNode* root) {
        ostringstream out;
        serialize(root, out);
        return out.str();
    }

    TreeNode* deserialize(string data) {
        istringstream in(data);
        return deserialize(in);
    }

private:
    void serialize(TreeNode* root, ostringstream& out) {
        if (root) {
            string tmp = root->val;
            if(!tmp) out << "_*_" << "_#_";
            else if(tmp == "") out << "_%_" << "_#_";
            else{
                int i = 0;
                while(i<tmp.size() && (tmp.find("#") || tmp.find("$") || tmp.find("*") || tmp.find("%") )){
                    if(tmp[i] == "#") {tmp.replace(i,1,"# #");i+=2;}
                    else if(tmp[i] == "$") {tmp.replace(i,1,"$ $");i+=2;}
                    else if(tmp[i] == "*") {tmp.replace(i,1,"* *");i+=2;}
                    else if(tmp[i] == "%") {tmp.replace(i,1,"% %");i+=2;}
                    i++;
                }
                out << tmp << "_#_";
            }
            serialize(root->left, out);
            serialize(root->right, out);
        } else {
            out << "_$_" << "_#_";
        }
    }

    TreeNode* deserialize(istringstream& in) {
        string tmp;
        getline(in,tmp,"_#_");
        TreeNode* root = nullptr;
        if (tmp != "_$_"){
            string val = NULL;
            if(tmp == "_%_") val = "";
            else {
                int i = 0;
                while(i<tmp.size()-2 && (tmp.find("# #") || tmp.find("$ $") || tmp.find("* *") || tmp.find("% %") )){
                    if(tmp.substr(i,3) == "# #") tmp.replace(i,3,"#");
                    else if(tmp.substr(i,3) == "$ $") tmp.replace(i,3,"$");
                    else if(tmp.substr(i,3) == "* *") tmp.replace(i,3,"*");
                    else if(tmp.substr(i,3) == "% %") tmp.replace(i,3,"%");
                    i++;
                }
                val = tmp;
            }
            root = new TreeNode(val);
            root->left = deserialize(in);
            root->right = deserialize(in);
        }
        return root;
    }
};
       

有一轮面试: 问了一个House Robber(LC 198)的二维推广版, 就是给一个 n x m 2d array, 每个位置代表房子的金额 >= 0, 如果偷了一个房子, 则周围八个房子都不能偷, 问能偷到的最大金额是多少?  
        X 1349

评分

参与人数 2大米 +4 收起 理由
CeliaYa + 2 很有用的信息!
salinghang17 + 2 tal

查看全部评分

回复

使用道具 举报

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

本版积分规则

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