摘要: Q: from given array of n elements find the maximum element for each consecutive sub-array of k elements.eg.array=[6,5,4,3,2,1]k=3ans=6 5 4 3explanation:6 from array [6,5,4]5 from array [5,4,3]4 from array [4,3,2]3 from array [3,2,1]A:void max_element_of_subarr(int a[], int n, int k){ for(int m=0;... 阅读全文
posted @ 2013-03-20 09:50 百分百好牛 阅读(216) 评论(0) 推荐(0) 编辑
摘要: 下载好gtest-1.6.0,然后解压到一个目录下,比如e:\gtest-1.6.0如果大家尝试着用VS2012 去编译GTest (e:\gtest-1.6.0\msvc\gtest.sln),可能会碰到下面的编译错误:\gtest\include\gtest\gtest-printers.h(550): error C2977: 'std::tuple' : too many template arguments可是,怎么解决呢?Q:用VS2012打开gtest.sln,会提示升级,不用管,一路YES下去。然后打开project的properties -> C\C++ 阅读全文
posted @ 2013-03-10 10:58 百分百好牛 阅读(2851) 评论(0) 推荐(1) 编辑
摘要: google 面试 准备 清单 阅读全文
posted @ 2013-02-22 15:52 百分百好牛 阅读(715) 评论(0) 推荐(0) 编辑
摘要: Have an arraywe have to find longest subarray with consecutive numbersex [4,5,34,33,32,11,10,31]answer is[31,32,33,34][92 26 30 28 27]answer is [27, 28]NOT [26, 27, 28]because 26, 27, and 28 are not in a contiguous subarray 阅读全文
posted @ 2013-01-25 16:37 百分百好牛 阅读(126) 评论(0) 推荐(0) 编辑
摘要: Q:假设你可以回到昨天,并且得到股市昨天的全天每个时刻的数据,你能够通过买卖交易,赚取最多的钱么?比如:1. {10, 20, 15, 18, 22, 20, 4, 5}{买入 卖出} {10, 20} {15, 22} {4, 5} 一共三次交易,赚了 10 + 7 + 1 = 18块钱2. {5, 10, 9, 10, 11, 11, 12, 100}{5, 10} {9, 100} 两次交易,赚了 5 + 91 = 96,是最多的钱。条件:1. 不计手续费2. 一次买+卖算一次完整交易3. 买入后,在卖出前,不能再买入(意思是,交易不能交叉)问题:1. 如果没有其它限制,只让你尽可能多的 阅读全文
posted @ 2013-01-25 15:08 百分百好牛 阅读(175) 评论(0) 推荐(0) 编辑
摘要: The following is an implementation of the CMWC algorithm in theC programming language. Also, included in the program is a sample initialization function. In this implementation the lagr=4096. The period of the resulting generator is about.#include <stdint.h> #define PHI 0x9e3779b9 static uint3 阅读全文
posted @ 2013-01-25 10:30 百分百好牛 阅读(439) 评论(0) 推荐(0) 编辑
摘要: Q:Given an integer, return all sequences of numbers that sum to it. (Example: 3 -> (1, 2), (2, 1), (1, 1, 1)).A:class CalcSequenceNumber{private: static void print(int values[], int n) { for (int i = 0; i < n; ++i) // n may be less then length of values[] { cout << " "... 阅读全文
posted @ 2013-01-23 16:24 百分百好牛 阅读(641) 评论(0) 推荐(0) 编辑
摘要: Q:What will be the change in complexity if we will choose 2 and 3 pivots in the quicksort algorithm ?The exact complexity and why ??A:if we use 2 element as a pivot (suppose 1st and last element) then we partisan the array into three part and we use quick shot in every partisanSo the new recurrence 阅读全文
posted @ 2012-06-25 10:55 百分百好牛 阅读(197) 评论(0) 推荐(0) 编辑
摘要: Two sorted array. Find kth smallest elementO(logK)A:Compare A[k/2] and B[k/2].If A[k/2] < B[k/2], it means these A[1] to A[k/2] elements are part of first k elements.Now, the kth element can be in A[k/2 + 1] to A[k] or B[1] to B[k/2]. (note: here may be B[1] to B[k], *not* B[k/2])Hence, we reduce 阅读全文
posted @ 2012-06-25 10:46 百分百好牛 阅读(637) 评论(0) 推荐(0) 编辑
摘要: Q:Given an array of positive and negative integers find the first subarray with zero sum?no 0's will be a part of the input array and handle all the edge casesA:1. iterate through the array once, and take the sum from 0 to every other index of the array.2. If any sum is zero, the subarray from 0 阅读全文
posted @ 2012-06-24 19:23 百分百好牛 阅读(570) 评论(0) 推荐(0) 编辑