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

非死不可店面, 挂

全局:

2018(10-12月) 码农类General 博士 全职@meta - 内推 - 技术电面  | | Other | 在职跳槽

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

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

x
EE职位。

题目:
input: String[] words, char[] orders
output: if the words are in the order define
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
e/smiley/QQ/em03.gif" smilieid="85" border="0" alt="" />。应该挂了吧。



评分

参与人数 2大米 +10 收起 理由
drool + 5 给你点个赞!
Vicmal + 5 很有用的信息!

查看全部评分


上一篇:facebook 面经 + 关于coding和system design的一点心得
下一篇:Coursera OA
全局:
写了一下,但是前提条件是所有vector里面的字符都包含在字典order里面。。不知道对不对
/*
input: String[] words, char[] orders
output: if the words are in the order defined by orders.

for example:. 1point 3acres 论坛
["cc", "cb", "ab"], {c, b, a}  => true

["cc", "cb", "ab"], {b, c, a}  => false
*/
bool check(string s1, string s2, unordered_map<char,int> m)
{
    if(s1 == s2)return true;
    int len = s1.size() > s2.size() ? s2.size() : s1.size();
    for(int i = 0; i < len; i++)
    {
        if(m[s1[i]] > m[s2[i]])return false;
        if(m[s1[i]] < m[s2[i]])return true;
    }
    return s2.size() > len ? true : false;
}
bool valid(vector<string> v, vector<char> dict)
{
    unordered_map<char,int> m;
    for(int i = 0; i < dict.size(); i++)
    {
        m[dict[i]] = i;
    }
    for(int i = 1; i < v.size(); i++)
    {
        if(!check(v[i - 1], v[i], m))return false;
    }
    return true;
}

int main() {
        // your code goes here
        vector<string> v1 = {"cc", "cb", "ab"};
        vector<string> v2 = {"cc", "cb", "ab"};
        vector<char> dict1 = {'c', 'b', 'a'};
        vector<char> dict2 = {'b', 'c', 'a'};
        cout<<valid(v1, dict1)<<endl;
        cout<<valid(v2,dict2)<<endl;
        return 0;
}
回复

使用道具 举报

推荐
 楼主| jih23 2018-11-9 09:24:05 | 只看该作者
全局:
Vicmal 发表于 2018-11-8 10:59
请问下楼主给的什么解法?感觉这道题只能比较相邻的 然后for 每个位置的字符 看每个字符在给的order里面对 ...

我差不多是这么写的,
foreach words[i-1] , words[i] pair, find the first characters of words[i-1] and words[i] from left and compare if words[i-1][j] < words[i][j].
烙印不理解,他觉得需要先对每个词的第一个char比较,然后第二个char。类似radix sort,我觉得没那么复杂。

补充内容 (2018-11-9 10:48):
有些自动格式问题,补充一下以免误解。
foreach words[i-1] , words【i】  pair, find the first characters of words[i-1] and words【i】 from left and compare if words[i-1][j] < words【i】[j].
回复

使用道具 举报

推荐
Vicmal 2018-11-9 09:29:55 | 只看该作者
全局:
jih23 发表于 2018-11-9 09:24
我差不多是这么写的,
foreach words , words pair, find the first characters of words and words fr ...

遇到这种烙印也没办法,楼主应该给他解释了比较可以传递的。。这道题只需要返回true或者false就可以了,如果需要重新排序才需要radix sort,这烙印有毒. 楼主加油!
回复

使用道具 举报

🔗
Vicmal 2018-11-8 10:59:32 来自APP | 只看该作者
全局:
请问下楼主给的什么解法?感觉这道题只能比较相邻的 然后for 每个位置的字符 看每个字符在给的order里面对应的rank 返回true or false就好了 烙印是要什么样的解法呢 谢谢楼主 加米了
回复

使用道具 举报

🔗
drool 2018-11-8 11:08:42 来自APP | 只看该作者
全局:
用trie 吧 每节点记录和以前visit过的最大的比 不能更小

评分

参与人数 1大米 +3 收起 理由
serenitype + 3 很有用的信息!

查看全部评分

回复

使用道具 举报

🔗
drool 2018-11-8 11:10:12 来自APP | 只看该作者
全局:
电话通知你了吗?可能加面

评分

参与人数 1大米 +3 收起 理由
serenitype + 3 给你点个赞!

查看全部评分

回复

使用道具 举报

🔗
mingzhou1987 2018-11-8 11:11:17 | 只看该作者
全局:
祝楼主好运,不是太理解第一个例子,为什么“ab" 还是return true,能解释一下嘛?
回复

使用道具 举报

全局:
twopointers的题吧…?
回复

使用道具 举报

🔗
heyuan_alex 2018-11-8 11:29:03 | 只看该作者
全局:
有点像alien words, 只不过变成判断valid而不是找一个顺序了
回复

使用道具 举报

全局:
mingzhou1987 发表于 2018/11/08 11:11:17
祝楼主好运,不是太理解第一个例子,为什么“ab" 还是return true,能解释一下嘛?

这个例子能够得出c在b前面,c在a前面,a和b的顺序随意所以是true
回复

使用道具 举报

🔗
qingli.tamu 2018-11-8 14:15:24 | 只看该作者
全局:
leetcode 791, custom stor string.
回复

使用道具 举报

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

本版积分规则

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