楼主: 匿名
跳转到指定楼层
上一主题 下一主题
收起左侧

[3/8] Google Onsite

地里匿名用户
🔗
匿名用户-BOOYB  2016-3-29 07:23:48
bobzhang2004 发表于 2016-3-29 05:21
请问” count of smaller number before itself“ 这个题楼主是选择建树还是divide and conquer,面试官对 ...

我建了树,满意

评分

参与人数 1大米 +3 收起 理由
bobzhang2004 + 3 回答的很好!

查看全部评分

回复

使用道具 举报

地里匿名用户
🔗
匿名用户-BOOYB  2016-3-29 07:24:38
bobzhang2004 发表于 2016-3-29 05:22
楼主可以给下“求最大能获取的假期和Path. ”的具体代码吗?看到很多次这个题,但还是不清楚具体怎么做

不想写了,但是dp公式都给了,应该不需要具体代码了吧。。。。path的话就track一下就行
回复

使用道具 举报

🔗
bobzhang2004 2016-3-29 12:46:35 | 只看该作者
全局:
论坛匿名用户 发表于 2016-3-29 07:23
提示一下,不想说太细了,看看java中round函数是什么样的,怎么实现的

The java.lang.Math.round(float a) returns the closest int to the argument. The result is rounded to an integer by adding 1/2, taking the floor of the result, and casting the result to type int.
回复

使用道具 举报

🔗
bobzhang2004 2016-3-29 12:49:40 | 只看该作者
全局:
论坛匿名用户 发表于 2016-3-11 06:24
比如2f 最接近 33对吧,所以就转换成33, 3d 最接近33也转换成33,比如5a->66
findNthsmallest element  ...

那就建一个sorted array, 然后将输入的指通过二分查找找到那个最近的值就行了吧,将3d都这些都转化为十进制,然后查找
回复

使用道具 举报

🔗
bobzhang2004 2016-3-29 12:50:37 | 只看该作者
全局:
machen982003 发表于 2016-3-13 04:12
那这个题是扫四遍的做法么? 做一遍右一遍, 上一遍下一边, 然后求和最大?

分享下代码吧
  1. public class FlowersInGarden {

  2.         public static void main(String[] args) {
  3.                 char[][] matrix = {{'f', 'x', 'x', 'w', 'f'},
  4.                                      {'f', 'f', 'x' ,'x' ,'x'},
  5.                                      {'x', 'x', 'f', 'w', 'f'},
  6.                                      {'f', 'f', 'x', 'w', 'x'}};
  7.                 maxFlowersInGarden(matrix);
  8.         }
  9.        
  10.         public static int maxFlowersInGarden(char[][] matrix) {
  11.                 if (matrix == null || matrix.length == 0 || matrix[0].length == 0) {
  12.                         return 0;
  13.                 }
  14.                 int m = matrix.length;
  15.                 int n = matrix[0].length;
  16.                
  17.                 int[][] res = new int[m][n];
  18.                 for (int i = 0; i < m; i++) {
  19.                         int count = 0;
  20.                         int j = 0;
  21.                         int start = 0;
  22.                         while (j < n) {
  23.                                 if (matrix[i][j] == 'f') {
  24.                                         count++;
  25.                                 } else if (matrix[i][j] == 'w') {
  26.                                         for (int k = start; k < j; k++) {
  27.                                                 res[i][k] = count;
  28.                                         }
  29.                                         start = j + 1;
  30.                                         count = 0;
  31.                                 }
  32.                                 j++;
  33.                         }
  34.                         for (int k = start; k < j; k++) {
  35.                                 res[i][k] = count;
  36.                         }
  37.                 }
  38.                 for (int j = 0; j < n; j++) {
  39.                         int count = 0;
  40.                         int i = 0;
  41.                         int start = 0;
  42.                         while (i < m) {
  43.                                 if (matrix[i][j] == 'f') {
  44.                                         count++;
  45.                                 } else if (matrix[i][j] == 'w') {
  46.                                         for (int k = start; k < i; k++) {
  47.                                                 res[k][j] += count;
  48.                                         }
  49.                                         start = i + 1;
  50.                                         count = 0;
  51.                                 }
  52.                                 i++;
  53.                         }
  54.                         for (int k = start; k < i; k++) {
  55.                                 res[k][j] += count;
  56.                         }
  57.                 }
  58.                 for (int i = 0; i < m; i++) {
  59.                         for (int j = 0; j < n; j++) {
  60.                                 if (matrix[i][j] == 'f') {
  61.                                         res[i][j] -= 1;
  62.                                 }
  63.                         }
  64.                 }
  65.                 int max = 0;
  66.                 for (int i = 0; i < m; i++) {
  67.                         for (int j = 0; j < n; j++) {
  68.                                 System.out.print(res[i][j] + " ");
  69.                                 max = Math.max(max, res[i][j]);
  70.                         }
  71.                         System.out.println();
  72.                 }
  73.                
  74.                
  75.                 return max;
  76.         }
  77. }
复制代码
回复

使用道具 举报

🔗
bobzhang2004 2016-3-29 12:52:20 | 只看该作者
全局:
simplessssss 发表于 2016-3-28 09:53
请问楼主第五轮的第一题是怎么做的,怎么计算 slidingwindow avg, global avg, update(insert) value都可以 ...

update的意思就只能是加一个数吗?如果这样的话应该就是sliding window average的变形啊,就是多一个sum几轮全局的和就行了
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-BOOYB  2016-3-30 07:36:40
bobzhang2004 发表于 2016-3-29 12:49
那就建一个sorted array, 然后将输入的指通过二分查找找到那个最近的值就行了吧,将3d都这些都转化为十进 ...

你想想怎么用java的round logic on 这道题,很简单,O(1)时间就能做出来
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-BOOYB  2016-3-30 07:37:29
bobzhang2004 发表于 2016-3-29 12:52
update的意思就只能是加一个数吗?如果这样的话应该就是sliding window average的变形啊,就是多一个sum ...

嗯,对,就是变形应该
回复

使用道具 举报

🔗
kittycerry 2016-4-10 12:57:28 | 只看该作者
全局:
slidingwindow avg, global avg, update(insert) value 怎样能达到o(1)?

这个数据结构不能用array吧?用array的话,insert不能达到o(1)吧?如果用segment tree, 也都不是o(1),如果用linked list的话,插入可以o(1),别的怎么达到o(1)呢?
回复

使用道具 举报

🔗
jy_121 2016-4-25 12:37:40 | 只看该作者
全局:
假期那题楼主可以再说一下吗,没看懂题目。谢谢
回复

使用道具 举报

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

本版积分规则

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