收到ThoughtWorks的面试邀请,HR电话初面后,说是要做题。

给发了3道题,任选一道。

ThoughtWorks是什么样的公司呢?外企,听说很牛,什么“敏捷开发模式”就是那公司

首创的概念。出的题目也有些奇怪,选取第一道如下:

Problem one: Trains

The local commuter railroad services a number of towns in Kiwiland. Because of monetary concerns, all of the tracks are ‘one-way.’ That is, a route from Kaitaia to Invercargill does not imply the existence of a route from Invercargill to Kaitaia. In fact, even if both of these routes do happen to exist, they are distinct and are not necessarily the same distance!

The purpose of this problem is to help the railroad provide its customers with information about the routes. In particular, you will compute the distance along a certain route, the number of different routes between two towns, and the shortest route between two towns.

Input: A directed graph where a node represents a town and an edge represents a route between two towns. The weighting of the edge represents the distance between the two towns. A given route will never appear more than once, and for a given route, the starting and ending town will not be the same town.

Output: For test input 1 through 5, if no such route exists, output ‘NO SUCH ROUTE’. Otherwise, follow the route as given; do not make any extra stops! For example, the first problem means to start at city A, then travel directly to city B (a distance of 5), then directly to city C (a distance of 4).

  1. The distance of the route A-B-C.
  2. The distance of the route A-D.
  3. The distance of the route A-D-C.
  4. The distance of the route A-E-B-C-D.
  5. The distance of the route A-E-D.
  6. The number of trips starting at C and ending at C with a maximum of 3 stops. In the sample data below, there are two such trips: C-D-C (2 stops). and C-E-B-C (3 stops).
  7. The number of trips starting at A and ending at C with exactly 4 stops. In the sample data below, there are three such trips: A to C (via B,C,D); A to C (via D,C,D); and A to C (via D,E,B).
  8. The length of the shortest route (in terms of distance to travel) from A to C.
  9. The length of the shortest route (in terms of distance to travel) from B to B.
  10. The number of different routes from C to C with a distance of less than 30. In the sample data, the trips are: CDC, CEBC, CEBCDC, CDCEBC, CDEBC, CEBCEBC, CEBCEBCEBC.

Test Input:

For the test input, the towns are named using the first few letters of the alphabet from A to D. A route between two towns (A to B) with a distance of 5 is represented as AB5.

Graph: AB5, BC4, CD8, DC8, DE6, AD5, CE2, EB3, AE7

Expected Output:

Output #1: 9

Output #2: 5

Output #3: 13

Output #4: 22

Output #5: NO SUCH ROUTE

Output #6: 2

Output #7: 3

Output #8: 9

Output #9: 9

Output #10: 7

看题目,一开始摸不着头脑,甚至用了翻译琢磨。做完第一道提交了,具体对不对,

估计不好说。现把自己总结的解题思路写下来,留个念。

问题大致分5类:

1.求路径距离;
2.给定起始点,求路径条数;
3.给定遍历深度,求路径条数;
4.给定路径长度,求路径条数;
5.求最短路径

这道题考察的基础有很多:

1.项目结构

  • 包的分类,命名
  • 业务分层
  • 依赖管理

2.数据结构设计

  • 数据定义
  • 选择哪几种集合
  • 集合的使用方法

3.程序设计

  • 遍历,查找
  • 复杂度

4.异常处理

  • 自定义异常
  • 抛出异常

5.单元测试

1.项目结构

项目结构,分了entity,service,test,exception等几个包,分别存放不同功能的class。依赖,最好使用maven做依赖管理。

2.数据结构设计

定义了town(城镇),route(路线)等基本对象。集合选择,(k,v)结构的,使用HashMap;单纯的无序集合,使用HashSet;集合的随机修改,用到了LinkedList,对集合的随机查找,遍历,也用到了ArrayList。

3.程序设计

大致知道程序需要用到深度遍历,广度遍历等思路。我看了二叉树的遍历,说是,广度遍历,是使用队列;深度遍历,是
使用堆栈。但这里,其实是树遍历,其实还用到迭代遍历。迭代遍历不好理解。总之,也借鉴了别人的设计。

我也想到了复杂度这一点。O(N)当然是最好。但既有树遍历,又有迭代遍历,复杂度是O(N)的N次方。感觉这点无解,之前做的少,不知道有什么优化版本。查找的话,个人倾向for循环遍历。

4.异常处理

应该是要自定一个异常,然后打印输出异常情况。后来想,应该把打印输出,也写在自定异常类里面。可是提交答案的时候,忘记做了。

异常使用throw关键字。没有用try catch

5.单元测试

这里面,一开始我以为很简单,但看了下别人的处理,感觉这里的细节也很多。诸如类的初始化,注解的使用,测试方法的排序。

总之,这道题考察的基础有很多,除了上面提到的,应该还有一些,限本人能力,一时还看不出。就先记下吧。

ThoughtWorks笔试题大致解题思路总结相关推荐

  1. c语言填空题删除字符串k右边,计算机二级C语言上机模拟试题及解题思路

    计算机二级C语言上机模拟试题及解题思路 随着2017年上半年计算机等级考试的临近,百分网小编为大家整理了2017计算机二级C语言上机模拟试题及解题思路,更多计算机等级考试信息请关注应届毕业生考试网. ...

  2. 计算机等级考试二级vfp上机试题及解题思路,计算机等级考试二级vfp上机模拟试题...

    计算机等级考试二级vfp上机模拟试题 计算机等级考试二级计算机等级考试二级上机模拟试题(上机模拟试题()一.基本操作题一.基本操作题(共四小题,第和题是分.第和题是分)在考生目录下完成如下操作:创建一 ...

  3. thoughtworks 笔试题及答案

    我自己做的火车题目答案,供大家参考 火车题目答案:https://download.csdn.net/download/xiananliu/10477156 Hi, It was great spea ...

  4. 华为2018软件岗笔试题解题思路和源代码分享

    2017年9月26日,参加了华为技术有限公司的笔试,题目类型是软件题,没有选择填空问答类型,总共是3道编程题目,题目难度适中,在两个小时内完成3道题目的AC,所以分享的代码都是可运行且完全AC的! 和 ...

  5. 从BAT面试题谈前端面试解题思路

    从BAT面试题谈前端面试解题思路 2009 年我在支付宝做前端开发时,参与草拟了一份非正式的前端岗位招聘要求. 这里有: 1.国内最大的第三方支付舞台,体验亿万资金穿梭代码的快感: 2.一群热爱前端技 ...

  6. 2020最新中高阶Android面试题总结 下(附解题思路)

    写在前面 这些面试题是我在去年换工作的时候整理,没有重点.包括java基础,数据结构,网络,Android相关等等. 适合3-5年工作经验,打算跳槽面试的中高级工程师.由于内容过多,将会分为上下两部分 ...

  7. 试题 算法训练 九宫格的奥(解题思路与代码)

    试题 算法训练 九宫格的奥(解题思路与代码) 解题思路 解题思路 通过题目我们了解到此题有三个小题,分别代表不同的功能,但总的功能就是,判断九宫格里面的数字还原成"标准型"九宫格时 ...

  8. 2014-百度 阿里 华为笔试题

    8月15日,百度2道面试题: 1.来自<编程之美>的概率题:一个桶里面有白球.黑球各100个,现在按下述规则取球:的     i .每次从通里面拿出来两个球:     ii.如果取出的是两 ...

  9. 最新百度 阿里 华为 腾讯 谷歌面试笔试题及解析

    最新百度 阿里 华为 腾讯 谷歌面试笔试题及解析 8月15日,百度2道面试题: 1.来自<编程之美>的概率题:一个桶里面有白球.黑球各100个,现在按下述规则取球:的 i .每次从通里面拿 ...

  10. 百度 阿里 华为 腾讯 谷歌面试笔试题及解析

    8月15日,百度2道面试题: 1.来自<编程之美>的概率题:一个桶里面有白球.黑球各100个,现在按下述规则取球:的     i .每次从通里面拿出来两个球:     ii.如果取出的是两 ...

最新文章

  1. matlab二维度矩阵转化三维_Matlab三维矩阵运算
  2. linux 当前用户执行定时任务
  3. USACO-Section1.5 Arithmetic Progressions(枚举)
  4. 为什么学计算机的人不用360,为什么会电脑的人都鄙视他人安装360?
  5. SQL Server跨库访问
  6. Ubuntu安装dos2unix命令
  7. 7-27 冒泡法排序 (20分)
  8. ps3 自制系统的C 语言,老树发新芽:PS3自制系统的使用与研究
  9. VBox下频繁出现0x00000000指令引用的0x00000000内存,该内存不能为written:解决方案(附文件)
  10. java 调用百度语音
  11. php 自适应 博客,三种方法让网站背景自动适应各浏览器大小
  12. JDK 17:Java 17 中的新特性
  13. PAAS容器安全防护
  14. Timed-Elastic-Band局部路径规划算法
  15. 专业的web打印插件
  16. (二)操作系统的发展与分类
  17. Oracle10g SQL分页查询写法与效率比较
  18. 19美亚个人赛复盘2(手机取证)
  19. EasyRecovery15数据恢复软件相关使用教程
  20. 斐波拉契数列通项公式

热门文章

  1. vulnhub--ALFA: 1
  2. Spring Boot + WebSocket实现网页在线实时聊天
  3. win7文件扩展名被隐藏无法修改文件格式怎么办?
  4. oracle常见的经典查询语句(一)
  5. 网络基础(五)------静态路由--实操
  6. Git拉代码(https以及ssh两种)
  7. 深度学习之训练误差和泛化误差
  8. linux禁用137 138端口,如何关闭135、137、138、139、445端口方法
  9. 论文翻译(上):Deep Learning Based Semantic Labelling of 3D Point Cloud in Visual SLAM
  10. CS231n Assiganment#1-KNN 代码解析