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

阅后即焚的新鲜店面

全局:

2016(4-6月) 码农类General 硕士 全职@snapchat - 内推 - 技术电面  | | Other | 应届毕业生

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

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

x
前天面的,现在还没消息。发面经攒人品求过呀。店面第一轮,是非常友好的国人小哥,非常耐心的给了很多提示。。如果小哥你也看到这贴了,求给我个加面吧。。非常想去的公司啊。。
第一提,给你你个数组,要你返回数组的最小值的平方是否小于最大值。题目很简单,需要注意的就是最小
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
这上面是可以run的。。哎,当时不知道啊。。提醒一下大家。我就奇怪当时小哥怎么说,我们写几个test case来跑一下看看。。然后我用人工给他run了几个

评分

参与人数 4大米 +39 收起 理由
bryanjhy + 3 给你点个赞!
恋恋牧羊女1 + 1 很有用的信息!
Rain + 5 感谢分享!
夏虫不知雪花 + 30

查看全部评分


上一篇:MathWorks实习店面+HR
下一篇:有面试过MarkLogic的同学吗?~

本帖被以下淘专辑推荐:

推荐
ykwwind 2016-5-6 01:34:24 | 只看该作者
全局:
第一问不说了;
第二问从尾巴往前;
第三问第一反应bottom up-DP, 想了下...线段树查最小值啊?
回复

使用道具 举报

推荐
dili7743 2016-5-19 10:22:16 | 只看该作者
全局:
jy_121 发表于 2016-5-19 05:26
请问最后一问的DP方程应该怎样写呢?谢谢

C++代码:

  1. /*
  2. * Given an array. Check whether 2 power the minimum of the array is larger then the maximum of the array.
  3. * follow up 1: (minTakesFront)     If you can take out the front elements in the array, how many steps it takes to make the rest of the array satisfying the above condition?
  4. * follow up 2: (minTakesBothEnds)  what if you can take out elements from both ends of the arrary? Then what is the minimum steps to find a subarray that satisfying the above condition?
  5. */

  6. #include <iostream>
  7. #include <string>
  8. #include <vector>
  9. #include <algorithm>
  10. #include <limits>

  11. using namespace std;

  12. bool checkPow(const int& minValue, const int& maxValue) {
  13.     errno = 0;
  14.     double pow2 = std::pow( minValue, 2 );
  15.     if ( errno == 0 ) {
  16.         //  std::pow succeeded (without overflow)
  17.         if (pow2 > maxValue) {
  18.             return true;
  19.         }
  20.     } else {
  21.         //  some error (probably overflow) with std::pow.
  22.         return false;
  23.     }   
  24.     return false;
  25. }

  26. int minTakesFront(const vector<int>& nums) {
  27.         int minValue = numeric_limits<int>::max();
  28.         int maxValue = numeric_limits<int>::min();
  29.         int s = static_cast<int>(nums.size());
  30.         int i = s - 1;
  31.         for (; i >= 0 ; --i) {   
  32.                 minValue = min(nums[i], minValue);
  33.                 maxValue = max(nums[i], maxValue);
  34.                 if (!checkPow(minValue, maxValue)) {
  35.                         break;
  36.                 }
  37.         }
  38.         if (i == s - 1) {
  39.                 return -1;
  40.         }
  41.         return i + 1;
  42. }

  43. // return minimum steps to make a subarray inside the passed in array such that 2 power the minimum is larger the maximum
  44. // or -1 if there is no such subarray
  45. int minTakesBothEnds(const vector<int>& nums) {
  46.         int s = static_cast<int>(nums.size());
  47.        
  48.         if (s == 0) {
  49.             return -1;
  50.         }
  51.        
  52.         vector<vector<int>> f(s, vector<int>(s, 0));
  53.         for (int i = 0; i < s; ++i) {
  54.             if (checkPow(nums[i], nums[i])) {
  55.                 f[i][i] = 0;
  56.             } else {
  57.                 f[i][i] = 1;
  58.             }
  59.         }
  60.        
  61.         for (int i = s - 1; i >= 0; --i) {
  62.                 int minValue = nums[i];
  63.                 int maxValue = nums[i];
  64.                 for (int j = i + 1; j < s; ++j) {
  65.                         minValue = min(nums[j], minValue);
  66.                         maxValue = max(nums[j], maxValue);
  67.                         if (checkPow(minValue, maxValue)) {
  68.                                 f[i][j] = 0;
  69.                         } else {
  70.                                 f[i][j] = min(f[i + 1][j], f[i][j - 1]) + 1;
  71.                         }
  72.                 }
  73.         }
  74.        
  75.         //if steps equal to size of the array, all elements have been taken out
  76.         if (f[0][s - 1] == s) {
  77.             return -1;
  78.         }
  79.        
  80.         return f[0][s - 1];
  81. }

  82. int main()
  83. {
  84.   vector<int> test1 = {5};
  85.   vector<int> test2 = {1};
  86.   vector<int> test3 = {5, 1, 3};
  87.   vector<int> test4 = {1, 1, 1};
  88.   vector<int> test5 = {5, 3, 1};
  89.   vector<int> test6 = {2, 5, 3, 1};
  90.   vector<int> test7 = {-2};
  91.   vector<int> test8 = {1, 5, 3};
  92.   
  93.   cout << "test1 front result : " << minTakesFront(test1) << endl;
  94.   cout << "test2 front result : " << minTakesFront(test2) << endl;
  95.   cout << "test3 front result : " << minTakesFront(test3) << endl;
  96.   cout << "test4 front result : " << minTakesFront(test4) << endl;
  97.   cout << "test5 front result : " << minTakesFront(test5) << endl;
  98.   cout << "test6 front result : " << minTakesFront(test6) << endl;
  99.   cout << "test7 front result : " << minTakesFront(test7) << endl;
  100.   cout << "test8 front result : " << minTakesFront(test8) << endl;
  101.   cout << endl;
  102.   cout << "test1 both result : " << minTakesBothEnds(test1) << endl;
  103.   cout << "test2 both result : " << minTakesBothEnds(test2) << endl;
  104.   cout << "test3 both result : " << minTakesBothEnds(test3) << endl;
  105.   cout << "test4 both result : " << minTakesBothEnds(test4) << endl;
  106.   cout << "test5 both result : " << minTakesBothEnds(test5) << endl;
  107.   cout << "test6 both result : " << minTakesBothEnds(test6) << endl;
  108.   cout << "test7 both result : " << minTakesBothEnds(test7) << endl;
  109.   cout << "test8 both result : " << minTakesBothEnds(test8) << endl;
  110. }
复制代码
回复

使用道具 举报

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

使用道具 举报

🔗
GavinM 2016-5-6 01:24:35 | 只看该作者
全局:
问下楼主,第一个佛罗阿噗是从数组尾巴开始往前扫,然后每次记录最大值和最小值,然后求是否满足吗?这样应该是O(n),然后第二个的话,目前只能想到n方的方法,感觉应该有更好的办法- -
回复

使用道具 举报

🔗
 楼主| Mark6 2016-5-6 03:16:58 | 只看该作者
全局:
GavinM 发表于 2016-5-6 01:24
问下楼主,第一个佛罗阿噗是从数组尾巴开始往前扫,然后每次记录最大值和最小值,然后求是否满足吗?这样应 ...

对,由尾向前扫。。第三问我说的是用dp,dp(i, j)表示i到j的subarray是否满足,然后他接着问是否可以省空间。。。

评分

参与人数 1大米 +1 收起 理由
恋恋牧羊女1 + 1 给你点个赞!

查看全部评分

回复

使用道具 举报

🔗
ok123 2016-5-6 04:45:45 | 只看该作者
全局:
第二问,是不是题目不对。删除一个元素后,只有三中情况
1. 没有删到max min,关系不变
2. 删了min,第二min的平方更不可能小于max
3. 删了max,min平方更不可能小于第二max
回复

使用道具 举报

🔗
 楼主| Mark6 2016-5-6 04:57:41 | 只看该作者
全局:
ok123 发表于 2016-5-6 04:45
第二问,是不是题目不对。删除一个元素后,只有三中情况
1. 没有删到max min,关系不变
2. 删了min,第二 ...

元素可以为正,可以为负。
回复

使用道具 举报

🔗
 楼主| Mark6 2016-5-6 04:58:14 | 只看该作者
全局:
ok123 发表于 2016-5-6 04:45
第二问,是不是题目不对。删除一个元素后,只有三中情况
1. 没有删到max min,关系不变
2. 删了min,第二 ...

元素可以为正,可以为负。
回复

使用道具 举报

🔗
wtcupup 2016-5-18 18:50:02 | 只看该作者
全局:
给的数组是sorted的吗?
回复

使用道具 举报

🔗
jackyzhang 2016-5-18 22:10:33 | 只看该作者
全局:
请问第二问: 从前往后删和从后往前删的区别是?
我感觉如果不是sorted的话,没有区别啊,因为没法知道max和min会在哪。。。请大家指导
回复

使用道具 举报

🔗
 楼主| Mark6 2016-5-19 04:53:04 | 只看该作者
全局:
wtcupup 发表于 2016-5-18 18:50
给的数组是sorted的吗?

不是。。
回复

使用道具 举报

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

本版积分规则

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