An interview question from MicroStrategy
去年校招时的一道面试题,觉得蛮有意思,贴出来。
Question:
Spy start at a, during an interval he moves |b| to right when b >=0; moves |b| to left when b <0; I can ask the spy if he is in position x, if he is then I win.
Answer:
Here is how I analyze this problem:
1) First assume a = 0; then b could be 0, 1, 2….
i. |b| = 0 , I can guess 0 at first interval just caught the spy;
ii. |b| = 1 , then b could be 1 or -1, so I can guess 1 at first interval ; if not caught the spy, guess -2 at second interval and I will catch the spy;
iii. |b| = 2 , then b could be 2 or -2, so I can guess 2 at first interval ; if not caught the spy, guess -4 at second interval and I will catch the spy;
iv. ……
To sum it up ,I will take this list to catch the spy with n intervals,n start at 1:
0*1, 1*2, (-1)*3, (2)*4, (-2)*5, 3*6, (-3)*7, 4*8, (-4)*9 …… ((n/2)(-1)^n)*n;
2) But |a| can have many values not only zero ,when a=0,this is one-dimensional problem. We can regard (a, b) as a point in a Plane coordinate system .
This make the (a,b) in many squares, and we find the spy’s location from the most inside square to outside, and in every square we start at the point(|a|,0) as the red point showed in the picture. The same to the first problem is the time interval increases in Linear growth. And we can use the point’s value to calculate the location referenced to the point ,and can get the spy.
For example
1) (0,0): 0 + 0*1(this is the number of intervals);
2) (1,0): 1+ 0*2; (1,1): 1+ 1*3; (0,1): 0+ 1*4; (-1,1): -1+ 1*5……
3) As the picture shows;
An interview question from MicroStrategy的更多相关文章
- an interview question(1)
声明:本文为博主原创文章,未经博主允许不得转载. 以下是英文翻译: warnning: Copyright!you can't reprint this blog when you not get b ...
- Core Java Interview Question Answer
This is a new series of sharing core Java interview question and answer on Finance domain and mostly ...
- shit LeetCode interview Question
shit LeetCode interview Question https://leetcode.com/interview/1/ 有点晕,啥意思,没太明白,到底是要按什么排序呀? 去掉 标识符 不 ...
- JavaScript interview Question - Create a Array with two papameters without using loop!
JavaScript interview Question - Create a Array with two papameters without using loop! JavaScript - ...
- an interview question(4)
版权声明:本文为博主原创文章,未经博主允许不得转载. 写这篇博客前请让博主先吐糟下自己的PC. i3+2G内存+开了一上午=C盘剩下0字节+打开VS2012花了半个小时+一晚上的心情不好 吐槽完PC, ...
- an interview question(3)
最近看了些C面试题顺便复习一下C语言,现贴一些出来和大家分享. #include <stdio.h> void main () { ,,,,};--------- *(ptr++)+=; ...
- an interview question(2)
感觉现在好多面试题还是很注重基础的,今天面试时就遇到这题,回来一查后才知道此题是国内某著名通信公司的一道机试题:) 给定一个数组input[ ],如果数组长度n为奇数,则将数组中最大的元素放到 out ...
- Interview Question
HDS(11.16.2015): How to design an non-stop website like Google or Amazon? What design patterns are y ...
- Amazon Interview Question: Design an OO parking lot
Design an OO parking lot. What classes and functions will it have. It should say, full, empty and al ...
随机推荐
- SqlServer高级特性--游标
游标 用途:在数据很多的时候,如果在java代码中进行循环之后再进行更新数据,会造成频繁的连接数据库,耗费性能,所以就可以使用到游标 作用:查询出来的集合直接在SQL中进行遍历在进行更新 DECLAR ...
- 2018-2019-2 《网络对抗技术》Exp1 PC平台逆向破解 20165222
Exp1 PC平台逆向破解 1,掌握NOP, JNE, JE, JMP, CMP汇编指令的机器码 NOP:空指令,作用就是直接跳到下一指令.机器码为:90. JNE:判断0标志位,不等于0跳转.机器码 ...
- test20181024 hao
题意 分析 考场10分 直接\(O(nm)\)模拟即可. #include<cstdlib> #include<cstdio> #include<cmath> #i ...
- 使用docker 部署graylog集群
graylog 相比elk 有比较简单的方面,使用简单,配置简单,可视化工具是一体化的,比较方便 搭建使用docker,多主机部分,结合docker-compose 进行管理 具体docker 配置文 ...
- 关于CCRANDOM_0_1
CCRANDOM_0_1的范围是[0,1)包括0但不包括1 CCRANDOM_0_1() * 1400.0f / 100.0f是0-13 另外每次随机都是相同的数,要随机下种子 srand((unsi ...
- Spring Could与Dubbo、Docker、K8S
如果你是在一个中小型项目中应用Spring Cloud,那么你不需要太多的改造和适配,就可以实现微服务的基本功能.但是如果是在大型项目中实践微服务,可能会发现需要处理的问题还是比较多,尤其是项目中老代 ...
- [LeetCode系列] 最长回文子串问题
给定字符串S, 找到其子串中最长的回文字符串. 反转法: 反转S为S', 找到其中的最长公共子串s, 并确认子串s在S中的下标iS与在S'中的下标iS'是否满足式: length(S) = iS ...
- 【转】在Visual Studio中怎样快速添加代码段
原文网址:http://blog.csdn.net/yl2isoft/article/details/9735527 以前一直只知道,键入prop,再按两次tab键,会生成自动属性代码. 今天闲着无事 ...
- 【转】嵌入式Linux启动配置文件及脚本
原文网址:http://blog.csdn.net/shuaishuai80/article/details/6202497 使用Busybox制作根文件系统时,/etc目录非常重要,它包含了嵌入式L ...
- JAVA通过JDBC连接Oracle数据库详解【转载】
JAVA通过JDBC连接Oracle数据库详解 (2011-03-15 00:10:03) 转载▼http://blog.sina.com.cn/s/blog_61da86dd0100q27w.htm ...