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

[实习] Twitter online test

全局:

2014(4-6月)-CS本科+fresh grad 无实习或全职 | 内推| 码农类General实习@Twitter

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

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

x
前几天接收到twitter的面试通知,非常意外,而且正是final的时候,没有办法,只好硬着头皮上了;在codility 上面做了两题,第一题
做出来了,第二题挂了,最终结果也挂了 ..
第一题:
A positive integer N is given. The goal is to construct the shortest possible sequence of integers ending with N, using the following rules:
the first element of the sequence is 1; more specifically: A[0] = 1,
each of the following elements is generated by multiplying the previous element by 2 or increasing it by 1; more precisely: A = A[i−1] * 2 or A = A[i−1] + 1, for i ≥ 1.
For example, for N = 17, the shortest sequence is:
  A[0] = 1
  A[1] = 2
  A[2] = 4
  A[3] = 8
  A[4] = 16
  A[5] = 17
Write a function:
class Solution { public int solution(int N); }
that, given a positive integer N, returns the length of the shortest possible sequence of integers satisfying the above conditions and ending with N.

For example, given N = 17, the function should return 6, as explained above.
Assume that:
N is an integer within the range [1..2,147,483,647].
Complexity:
expected worst-case time complexity is O(log(N));
expected worst-case space complexity is O(1).
. ----
第二题:
是two dimesion array ,找equilibrium point.
稍后补充完整




上一篇:Two Sigma VS Yahoo
下一篇:求解答 System Engineer 的工作
推荐
 楼主| tyr034 2014-10-14 06:22:57 | 只看该作者
全局:
第一题可以这样做:. check 1point3acres for more.
int shortest(int n){
     int result = 0;
     while(n!=1 ){
          if(n % 2 !=0){
             result++;
         }
         n = n /2;
     . 1point3acres.com
         result ++;
} ..
   
      
      return result;
        

}. Waral dи,
回复

使用道具 举报

推荐
 楼主| tyr034 2014-10-14 06:35:11 | 只看该作者
全局:
第二题相当于是one dimensional array 的延伸-baidu 1point3acres
http://www.geeksforgeeks.org/equilibrium-index-of-an-array/
就是array中的一个值,它的上面的数加起来等于下面的,左边的数等于右边的。
找到所有的equilibrium points。-baidu 1point3acres
不知道有人知道怎么做嘛
回复

使用道具 举报

推荐
lsuper 2015-3-9 12:54:46 | 只看该作者
全局:
DP 每个cell保存上下左右的sum,从top left ->bottom right,更新上、左,然后bottom right -> top right 更新下、右
对吗?
回复

使用道具 举报

🔗
concurrency 2014-5-10 10:41:58 | 只看该作者
全局:
支持一下  期待第二题
回复

使用道具 举报

🔗
shire1989 2014-5-18 05:06:53 | 只看该作者
本楼:
全局:
第二题?
回复

使用道具 举报

🔗
Linzertorte 2014-5-18 10:42:07 | 只看该作者
全局:
第一题感觉就是看二进制有几位,以及这其中几位是1.
回复

使用道具 举报

🔗
shire1989 2014-5-20 06:57:18 | 只看该作者
全局:
求第二题目?
回复

使用道具 举报

🔗
pc1000a 2014-6-4 05:26:59 | 只看该作者
本楼:
全局:
第二题涅?
回复

使用道具 举报

🔗
pc1000a 2014-6-4 05:27:22 | 只看该作者
全局:
感谢分享 LZ补个第二题呗~
回复

使用道具 举报

🔗
davidwh 2014-10-29 00:25:30 | 只看该作者
本楼:
全局:
用DP吧~~~~~~
回复

使用道具 举报

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

本版积分规则

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