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

hbk oa

全局:

2015(7-9月) 码农类General 硕士 实习@HBK - 校园招聘会 - 在线笔试  | | Other |
这个公司真神奇,
先是电面做题,然后发oa,
oa不难,但给了4个小时。
而且就一个testcase。

您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
64789&size=300x300&key=5f20a58defd5f260&nocache=yes&type=fixnone[/img]


本帖子中包含更多资源

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

x

上一篇:【处女贴】Yelp面经,2015年3月最新,第一轮电面
下一篇:Amazon Onsite面经,2015年3月
推荐
ydxdad 2015-9-2 14:07:12 | 只看该作者
全局:
douya 发表于 2015-8-30 12:24
就按我说的那么做就好,他只有一个testcase,不大

谢谢了。。。顺便update一下,我onsite已挂,OA的时候没考到这个题。不过权当刷题自己做了下,没按你说的做,稍微麻烦了点,不过可能快那么一点
  1. #include <iostream>
  2. #include <climits>
  3. #include <string>
  4. using namespace std;

  5. /**
  6. * algorithm class to find the number with:
  7. * 1) base of 17 representation is palindrome
  8. * 2) base of 2 representation has 17 consective 1 bits
  9. */
  10. class findNextPNumber {
  11. public:
  12. /**
  13.   * @string input, input string representing a number using 17 as base
  14.   *       which has p form
  15.   * @return unsigned long long, return the next 17 based palidoromed number
  16.   *           which has at least 17 consecutive 1 bits
  17.   */
  18. unsigned long long findNextPNumber17Bits(const string& input) {
  19.   string cur = input;
  20.   string next;
  21.   while (1) {
  22.    next = nextPNumber(cur);
  23.    unsigned long long num = decode(next);
  24.    if (num == ULLONG_MAX) //
  25.     return 0;
  26.    if (count_consecutive_ones(num) >= 17) {
  27.     return num;
  28.    }
  29.    cur = next;
  30.   }
  31.   return 0;
  32. }
  33. private:
  34. /**
  35.   * Test if an input string contains all 'G's (16)
  36.   * if all is 'G', return true
  37.   * else return false
  38.   */
  39. bool isAll16s(const string &num) {
  40.   int n = num.size();
  41.   for (int i = 0; i < n; i++) {
  42.    if (num[i] != 'g')
  43.     return false;
  44.   }
  45.   return true;
  46. }
  47. ;
  48. /**
  49.   *  input a string with 17 as base and output
  50.   *  the value as 10 base
  51.   */
  52. unsigned long long decode(const string& in) {
  53.   unsigned long long result = 0;
  54.   int n = in.size();
  55.   for (int i = 0; i < n; i++) {
  56.    if (isdigit(in[i]))
  57.     result = result * 17 + in[i] - '0';
  58.    else
  59.     result = result * 17 + (10 + in[i] - 'a');
  60.   }
  61.   return result;
  62. }
  63. ;

  64. /**
  65.   *  count the maximum consecutive bits of 1s
  66.   */
  67. int count_consecutive_ones(unsigned long long input) {
  68.   int count = 0;
  69.   while (input) {
  70.    input = (input & (input << 1));
  71.    count++;
  72.   }
  73.   return count;
  74. }

  75. /**
  76.   * generate next p number
  77.   */
  78. string nextPNumber(const string& num) {
  79.   if (isAll16s(num))
  80.    return '1' + string(num.size(), '0') + '1';
  81.   int n = num.size();
  82.   int mid = n / 2;
  83.   int carry = 1;
  84.   int i = mid - 1;
  85.   int nums[n];
  86.   // decode of special chars
  87.   for (int i = 0; i < n; i++) {
  88.    if (isdigit(num[i]))
  89.     nums[i] = num[i] - '0';
  90.    else
  91.     nums[i] = 10 + num[i] - 'a';
  92.   }
  93.   int j;
  94.   // If there are odd digits, then increment
  95.   // the middle digit and store the carry
  96.   if (n % 2 == 1) {
  97.    nums[mid] += carry;
  98.    carry = nums[mid] / 17;
  99.    nums[mid] %= 17;
  100.    j = mid + 1;
  101.   } else
  102.    j = mid;

  103.   // Add 1 to the rightmost digit of the left side, propagate the carry
  104.   // towards MSB digit and simultaneously copying mirror of the left side
  105.   // to the right side.
  106.   while (i >= 0) {
  107.    nums[i] += carry;
  108.    carry = nums[i] / 17;
  109.    nums[i] %= 17;
  110.    nums[j++] = nums[i--]; // copy mirror to right
  111.   }
  112.   // encode to special chars
  113.   string result;
  114.   for (int i = 0; i < n; i++) {
  115.    if (nums[i] < 10)
  116.     result += (nums[i] + '0');
  117.    else
  118.     result += (nums[i] - 10 + 'a');
  119.   }
  120.   return result;
  121. }
  122. ;

  123. };
  124. int main() {
  125. string cur = "19b91";
  126. findNextPNumber solver;
  127. cout << solver.findNextPNumber17Bits(cur);
  128. return 0;
  129. }
复制代码
回复

使用道具 举报

推荐
MS_Joe 2016-1-10 05:08:47 | 只看该作者
全局:
请问这个“下一个具有这两个性质的数”,是说比这个大的数,在17-based里是palidromic的,在二进制里全是"1"的数吗?还是说在2进制*中间*至少有一段是带有17个1的,也就是说可以是11001111111111111111111111111111111111111100000这样的,只要中间有一段有连续17个1。还是说这两个性质可以是比如再19-based里是palindromic的,在2进制里有19个1?
回复

使用道具 举报

推荐
 楼主| douya 2015-9-3 00:37:28 | 只看该作者
全局:
ydxdad 发表于 2015-9-2 14:07
谢谢了。。。顺便update一下,我onsite已挂,OA的时候没考到这个题。不过权当刷题自己做了下,没按你说的 ...

嗯嗯,加油!我之前onsite也跪了,挺奇怪的公司
回复

使用道具 举报

🔗
nathanwong 2015-3-9 07:35:16 | 只看该作者
全局:
是HBK Capital Management 么?是挺奇葩的流程
回复

使用道具 举报

🔗
 楼主| douya 2015-3-9 09:24:18 | 只看该作者
全局:
nathanwong 发表于 2015-3-9 07:35
是HBK Capital Management 么?是挺奇葩的流程

嗯,是的
回复

使用道具 举报

🔗
xieqilu1989 2015-3-13 02:16:42 | 只看该作者
全局:
卧槽,居然这公司OA还有不同的题目,我的不是这个题目
回复

使用道具 举报

🔗
 楼主| douya 2015-3-13 09:35:52 | 只看该作者
全局:
xieqilu1989 发表于 2015-3-13 02:16
卧槽,居然这公司OA还有不同的题目,我的不是这个题目

是的,不一样啊。
回复

使用道具 举报

全局:
请问楼主最后结果如何?多谢!
回复

使用道具 举报

🔗
 楼主| douya 2015-7-11 12:58:11 | 只看该作者
全局:
@南岸的风 发表于 2015-7-9 09:02
请问楼主最后结果如何?多谢!

on site 跪了
回复

使用道具 举报

🔗
@南岸的风 2015-7-12 01:06:05 | 只看该作者
全局:
加油!题目里说next number 是指比131071大的数吗?可不可以就是检查二进制表示是18个1, 19个1的数,以此类推,对每一个验证是不是palindrom?
回复

使用道具 举报

🔗
ydxdad 2015-8-9 14:19:32 | 只看该作者
全局:
楼主,这题找到unsigned long long也没找到啊,请问你是咋解决的啊
回复

使用道具 举报

🔗
 楼主| douya 2015-8-30 12:24:18 | 只看该作者
全局:
ydxdad 发表于 2015-8-9 14:19
楼主,这题找到unsigned long long也没找到啊,请问你是咋解决的啊

就按我说的那么做就好,他只有一个testcase,不大
回复

使用道具 举报

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

本版积分规则

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