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 ...
随机推荐
- Hibernate环境搭建+struts整合
说明:本文档,是和struts2+hibernate的整合示例. lib下还有struts2的jar包,本示例没有显示.struts2的搭建参考struts2的环境搭建 一下载hibernate的ja ...
- BZOJ1233 [Usaco2009Open]干草堆tower 和 BZOJ3549 [ONTAK2010]Tower
题意 Problem 3549. -- [ONTAK2010]Tower 3549: [ONTAK2010]Tower Time Limit: 10 Sec Memory Limit: 64 MBS ...
- RabbitMQ消息队列安装
[root@VM_119_179_centos ~]# rpm -ivh erlang-19.0.4-1.el6.x86_64.rpm [root@VM_119_179_centos ~]# rpm ...
- 开始SDK之旅-入门2-集成流程图、轨迹图到系统
http://bbs.ccflow.org/showtopic-2562.aspx 经测试,基本可用,还需增加 WF/Admin/pub.ascx 首先你得先理解流程图的数据的获取方式,其他的就很容易 ...
- bzoj4466 超立方体
Description 超立方体是立方体在高维空间内的拓展(其在 2 维情况下退化为正方形,1维情况下退化成线段).在理论计算机科学领域里,超立方体往往可以和 2 进制编码联系到一起.对理论计算机科学 ...
- 利用spring的ApplicationListener实现springmvc容器的初始化加载
1.我们在使用springmvc进行配置的时候一般初始化都是在web.xml里面进行的,但是自己在使用的时候经常会测试一些数据,这样就只有加载spring-mvc.xml的配置文件来实现.为了更方便的 ...
- 微信JS接口汇总及使用详解
这篇文章主要介绍了微信JS接口汇总及使用详解,十分的全面.详尽,包含分享到朋友圈,分享给朋友,分享到QQ,拍照或从手机相册中选图,识别音频并返回识别结果,使用微信内置地图查看位置等接口,有需要的小伙伴 ...
- 在Windows命令行窗口中输入并运行PHP代码片段(不需要php文件)的方法
有时候只是简单的为了测试某个php函数的效果,以前总是需要建一个php文件,复制这个文件的路径,再通过web访问或者用php命令执行这个php文件. 一直想要怎么才能不用创建文件,才能直接执行PHP代 ...
- 2017 年 PHP 程序员未来路在何方?
PHP 从诞生到现在已经有20多年历史,从Web时代兴起到移动互联网退潮,互联网领域各种编程语言和技术层出不穷, Node.js . GO . Python 不断地在挑战 PHP 的地位.这些技术的推 ...
- 一个检测网页是否有日常链接的python脚本
在大的互联网公司干技术的基本都会碰到测试.预发布.线上这种多套环境的,来实现测试和线上正式环境的隔离,这种情况下,就难免会碰到秀逗了把测试的链接发布到线上的情况,一般这种都是通过一些测试的检查工具来检 ...