🎁 长周末专享特惠!VIP通行证6个月立减$50,蓝莓立减$25 🎁
回复: 30
收起左侧

[facebook实习面试题目]f intern interview review, second round

本楼:   👍  0
0%
0%
0   👎
全局:   42
100%
0%
0

() @ - -   | | |

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

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

x
(45 minutes - 5 minutes chatting), 2 problems.
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
(n) time complexity o(1) space

上一篇:[facebook实习面试题目]F intern interview review, first round
下一篇:Amazon暑期实习第二轮电面
wwwyhx 2011-10-15 02:56:29 | 显示全部楼层
本楼:   👍  0
0%
0%
0   👎
全局:   177
88%
12%
25
怎么第二轮比第一轮简单这么多
回复

使用道具 举报

 楼主| Imbalism 2011-10-15 02:58:56 | 显示全部楼层
本楼:   👍  0
0%
0%
0   👎
全局:   42
100%
0%
0
第二题不会做。。。想了好久才想出来
回复

使用道具 举报

wwwyhx 2011-10-15 03:16:37 | 显示全部楼层
本楼:   👍  0
0%
0%
0   👎
全局:   177
88%
12%
25
void _inner_print(char* strOrg, char* strStart, int nLen)
{
        assert(strStart && nLen >= 0);

        if (0 == nLen)
        {
                cout<<strOrg<<endl;
                return;
        }

        char rec[256];
        memset(rec, 0, sizeof(rec)*sizeof(char));
       
        rec[*strStart]++;
        _inner_print(strOrg, strStart + 1, nLen - 1);
        for (int i = 1; i < nLen; i++)
        {
                if (rec[*(strStart + i)] != 0)
                        continue;

                rec[*(strStart + i)]++;

                swap(*strStart, *(strStart + i));
                _inner_print(strOrg, strStart + 1, nLen - 1);
                swap(*(strStart + i), *strStart);
        }
}

void PrintPerpetuation(char* str)
{
        assert(str);

        int nLen = strlen(str);
        _inner_print(str, str, nLen);
}

void test()
{
        char str[] = "abbcb";
        PrintPerpetuation(str);
}


15 min
回复

使用道具 举报

wwwyhx 2011-10-15 03:18:16 | 显示全部楼层
本楼:   👍  0
0%
0%
0   👎
全局:   177
88%
12%
25
证明 : 应为对于任何一个字符串来说, 他的下一步递归一定返回所有子串的全排列, 所以对于n个字符的字符串只需要保证被exclude的那个唯一即可
回复

使用道具 举报

wwwyhx 2011-10-15 03:19:45 | 显示全部楼层
本楼:   👍  0
0%
0%
0   👎
全局:   177
88%
12%
25
第二题不会做。。。想了好久才想出来
Imbalism 发表于 2011-10-15 02:58



    什么叫longest path?? 是经过根节点的那条吗??
回复

使用道具 举报

 楼主| Imbalism 2011-10-15 03:21:36 | 显示全部楼层
本楼:   👍  0
0%
0%
0   👎
全局:   42
100%
0%
0
回复 6# wwwyhx


     不是。。。任意的,careercup 里面有 答案 ,但是他说不能用那种方法
回复

使用道具 举报

wwwyhx 2011-10-15 03:22:47 | 显示全部楼层
本楼:   👍  0
0%
0%
0   👎
全局:   177
88%
12%
25
第二题不会做。。。想了好久才想出来
Imbalism 发表于 2011-10-15 02:58



    做后续遍历的递归, 对每个节点可以记录左子树的最大高度和右子树的最大高度, 当递归track back的时候可以得到对每个node做为turning point的时候得最大path, O(n)时间 O(1)空间
回复

使用道具 举报

 楼主| Imbalism 2011-10-15 03:28:41 | 显示全部楼层
本楼:   👍  0
0%
0%
0   👎
全局:   42
100%
0%
0
记录的高度存哪里?
回复

使用道具 举报

wwwyhx 2011-10-15 03:30:50 | 显示全部楼层
本楼:   👍  0
0%
0%
0   👎
全局:   177
88%
12%
25
记录的高度存哪里?
Imbalism 发表于 2011-10-15 03:28



    struct NODE
{
        NODE* pLft;
        NODE* pRgt;

        NODE() : pLft(NULL), pRgt(NULL) {}
};

int FindLongestPath(NODE* pRoot);

//Return Height
int _inner_find(NODE* pNode, int& nMaxPath)
{
        if (NULL == pNode)
                return 0;

        int nRet = 1;
        int nLft = _inner_find(pNode->pLft, nMaxPath);
        int nRgt = _inner_find(pNode->pRgt, nMaxPath);

        int nNew = 1 + nLft + nRgt;
        nMaxPath = nNew > nMaxPath ? nNew : nMaxPath;

        return 1 + nLft > nRgt ? nLft : nRgt;
}

int FindLongestPath(NODE* pRoot)
{
        assert(pRoot);

        int nMax = -1;
        _inner_find(pRoot, nMax);

        return nMax;
}
回复

使用道具 举报

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

本版积分规则

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