How to Rock an Algorithms Interview

本文提供了算法面试的实用建议,包括理解问题、提出初始解决方案、利用数据结构与算法知识、思考相关问题解决方法等策略。

转自:http://blog.palantir.com/2011/09/26/how-to-rock-an-algorithms-interview/


September 26th, 2011 | Kevin

Traveling salesman problem comic, originally from http://www.xkcd.com/399/
Comic courtesy of XKCD, via Creative Commons License

We do a lot of interviewing at Palantir, and let me tell you: it’s hard. I don’t mean that we ask tough questions (although we do). I mean that the task of evaluating a candidate is hard.

The problem? Given a whiteboard and one hour, determine whether the person across from you is someone you’d like to work with, in the trenches, for the next n years. A candidate’s performance during an interview is only weakly correlated with his or her true potential, but we’re stuck with the problem of turning the chickenscratch on the whiteboard into an ‘aye’ or ‘nay’. Sometimes it feels like a high-stakes game of reading tea leaves. Believe me we’re doing our best, but we’re often left the nagging worry that we’re passing up brilliant people who just had a bad day or who didn’t click with a particular problem.

In an effort to improve this situation, we wanted to write up a guide that will help candidates make sense of this process, or at least the part known as an Algorithms Interview. At Palantir we ask questions that test for a lot of different skills — coding, design, systems knowledge, etc. — but one of our staple interviews is to ask you to design an algorithm to solve a particular problem.

It usually starts like this:

Given X, figure out an efficient way to do Y.

First: Make sure you understand the problem. You’re not going to lose points asking for clarifications or talking through the obvious upfront. This will also buy you time if your brain isn’t kicking in right away. Nobody expects you to solve a problem in the first 30 seconds or even the first few minutes.

Once you understand the problem, try to come up with a solution – any solution whatever. As long as it’s valid, it doesn’t matter if your solution is trivial or ugly or extremely inefficient. What matters is that you’ve made progress. This does two things: (1) it forces you to engage with the structure of the problem, priming your brain for improvements you can make later, and (2) it gives you something in the bank, which will in turn give you confidence. If you can achieve a brute force solution to a problem, you’ve cleared a major hurdle to solving it in a more efficient way.

Now comes the hard part. You’ve given an O(n^3) solution and your interviewer asks you to do it faster. You stare at the problem, but nothing’s coming to you. At this point, there are a few different moves you can make, depending on the problem at hand and your own personality. Almost all of these can help on almost any problem:

  1. Start writing on the board. This may sound obvious, but I’ve had dozens of candidates get stuck while staring at a blank wall. Maybe they’re not visual people, but still I think it’s more productive to stare at some examples of the problem than to stare at nothing. If you can think of a picture that might be relevant, draw it. If there’s a medium-sized example you can work through, go for it. (Medium-sized is better than small, because sometimes the solution to a small example won’t generalize.) Or just write down some propositions that you know to be true. Anything is better than nothing.


  2. Talk it through. And don’t worry about sounding stupid. If it makes you feel better, tell your interviewer, “I’m just going to talk out loud. Don’t hold me to any of this.” I know many people prefer to quietly contemplate a problem, but if you’re stuck, talking is one way out of it. Sometimes you’ll say something that clearly communicates to your interviewer that you understand what’s going on. Even though you might not put much stock in it, your interviewer may interrupt you to tell you to pursue that line of thinking. Whatever you do, please DON’T fish for hints. If you need a hint, be honest and ask for one.


  3. Think algorithms. Sometimes it’s useful to mull over the particulars of the problem-at-hand and hope a solution jumps out at you (this would be a bottom-up approach). But you can also think about different algorithms and ask whether each of them applies to the problem in front of you (a top-down approach). Changing your frame of reference in this way can often lead to immediate insight. Here are some algorithmic techniques that can help solve more than half the problems we ask at Palantir:
    • Sorting (plus searching / binary search)
    • Divide-and-conquer
    • Dynamic programming / memoization
    • Greediness
    • Recursion
    • Algorithms associated with a specific data structure (which brings us to our fourth suggestion…)


  4. Think data structures. Did you know that the top 10 data structures account for 99% of all data structure use in the real world? Probably not, because I just made those numbers up — but they’re in the right ballpark. Yes, on occasion we ask a problem whose optimal solution requires a Bloom filter or suffix tree, but even those problems tend to have a near-optimal solution that uses a much more mundane data structure. The data structures that are going to show up most frequently are:
    • Array
    • Stack / Queue
    • Hashset / Hashmap / Hashtable / Dictionary
    • Tree / binary tree
    • Heap
    • Graph

    You should know these data structures inside and out. What are the insertion/deletion/lookup characteristics? (O(log n) for a balanced binary tree, for example.) What are the common caveats? (Hashing is tricky, and usually takes O(k) time when k is the size of the object being hashed.) What algorithms tend to go along with each data structure? (Dijkstra’s for a graph.) But when you understand these data structures, sometimes the solution to a problem will pop into your mind as soon as you even think about using the right one.


  5. Think about related problems you’ve seen before and how they were solved. Chances are, the problem you’ve been presented is a problem that you’ve seen before, or at least very similar. Think about those solutions and how they can be adapted to specifics of the problem at hand. Don’t get tripped up by the form that the problem is presented – distil it down to the core task and see if matches something you’ve solved in the past.


  6. Modify the problem by breaking it up into smaller problems. Try to solve a special case or simplified version of the problem. Looking at the corner cases is a good way to bound the complexity and scope of the problem. A reduction of the problem into a subset of the larger problem can give a base to start from and then work your way up to the full scope at hand.

    Looking at the problem as a composition of smaller problems may also be helpful. For example, “find a number in a sorted array which has been shifted cyclically by an unknown constant k” can be solved by (1) first figuring out “k” and then (2) figuring out how to perform binary search on a shifted array).


  7. Don’t be afraid to backtrack. If you feel like a particular approach isn’t working, it might be time to try a different approach. Of course you shouldn’t give up too easily. But if you’ve spent a few minutes on an approach that isn’t bearing any fruit and doesn’t feel promising, back up and try something else. I’ve seen more candidates who overcommit than undercommit, which means you should (all else equal) be a little more willing to abandon an unpromising approach.

Incidentally, trying out a few different approaches (rather than sticking with a single approach) tends to work well in interviews, because the problems we choose for an interview usually have many different solutions. Happily, the same is true for the problems we solve on the job =)



内容概要:本文系统性地介绍了Neo4j图数据库的技术体系、核心原理与企业级实战应用,涵盖从基础理论到生产落地的完整知识链条。深入剖析了Neo4j作为原生图数据库在存储架构、数据模型、查询语言(Cypher)方面的核心技术优势,重点讲解其基于节点、关系、属性的三元组模型和原生图存储机制,对比传统关系型数据库在处理复杂关联数据时的性能瓶颈。文档全面覆盖环境部署、工业级建模规范、Cypher深度编程、海量数据导入、Python/Java全栈开发集成、图算法分析(GDS)、高可用集群搭建及性能调优等内容,并通过金融风控知识图谱项目实现端到端的综合实战演练,提供可直接复用的建模模板、优化方案与故障排查手册。; 适合人群:具备一定数据库基础,从事大数据、人工智能、金融风控、知识图谱等相关领域的研发人员、架构师及数据工程师,尤其适合工作1-5年希望掌握图数据库企业级开发能力的技术人员。; 使用场景及目标:①掌握Neo4j在金融风控、社交网络、知识图谱等复杂关联场景下的建模与查询能力;②实现海量图数据的高效导入、集群部署与性能优化;③结合GDS图算法进行社群发现、路径分析、核心节点挖掘等智能分析任务;④构建前后端一体化的企业级图谱可视化系统。; 阅读建议:此资源强调工程化与生产级落地,建议结合实际项目边学边练,重点关注建模规范、索引设计、Cypher执行计划优化与集群运维等关键环节,配套源码与配置模板应作为开发参考标准使用。
代码下载链接: https://pan.quark.cn/s/a4b39357ea24 网站扒站工具,如标题所述,是用于复制或仿制网站内容的技术手段。 这些工具能够帮助用户抓取网站上的HTML代码、图片、CSS样式表、JavaScript文件等资源,以实现快速构建与原网站相似的新站点。 在IT行业中,这种行为有时被称为网页抓取或网页克隆,对于学习、分析或测试网站设计有着重要作用。 Teleport Ultra 是一款知名的扒站工具,它允许用户以一种系统化的方式下载整个网站到本地计算机上,以便离线查看或进一步分析。 以下是对Teleport Ultra及其功能的详细介绍: 1. **全面抓取**:Teleport Ultra能深入网站的每一个角落,不仅抓取首页,还能追踪链接,将整个网站的结构、内容和资源都下载下来。 这包括静态页面、动态内容、登录后的页面等。 2. **自定义设置**:用户可以设定抓取范围,例如只抓取特定目录,或者排除某些不想要的页面。 此外,还可以设置代理服务器,以匿名方式抓取,避免被目标网站检测到。 3. **时间调度**:对于大型或需要分时段抓取的网站,Teleport Ultra支持定时任务,可以在指定的时间自动开始抓取工作。 4. **内容过滤**:该工具允许用户过滤掉不需要的元素,如广告、脚本或图片,只保留核心内容。 5. **网站镜像**:完成抓取后,Teleport Ultra可以创建一个完整的网站镜像,包括所有链接关系,使得在本地浏览时体验与在线网站几乎一致。 6. **报告生成**:它还提供详细的抓取报告,包括未成功下载的页面、错误信息等,方便用户检查和修复问题。 7. **易于使用**:Teleport Ultra的界面直观,即使对编程不...
源码下载地址: https://pan.quark.cn/s/a4b39357ea24 Electron-Lark release-download-count 下载地址: Release electron 版的飞书 Feishu (原 Lark),对网页版本进行封装 相比起普通网页版,功能如下 独立的运行窗口,不容易误关闭 关闭程序时后台运行,隐藏到通知栏小图标,双击可重新打开界面 新消息提醒,状态栏小图标闪烁 解除浏览器限制,避免因浏览器版本不对而提示无法使用 已知问题 - 部分功能无法使用(工作台/会议等) - 飞书网页版缺陷,请向官方反馈 历史问题 - ~~ubuntu18.04 Gnome 桌面,锁屏之后,系统通知栏图标 Tray 会消失, 当前规避方案如下~~ - ~~当有新消息提醒的时候,会重置通知栏图标 tray,保证哪怕因为锁屏导致 tray 消失,在收到新消息之后也会重新出现并闪烁~~ - 使用 alt + shift + m 的快捷键,重新显示界面以及 dock 图标 - ~~V1.0.3 版本已修复,添加了一个 linux 锁屏监听,自动 reset appTray~~ - V1.1.1 版本升级了 electron 依赖,问题解决~ (另外有一说一, 飞书的技术架构就是基于 Electron 的, Windows 和 Mac 客户端也都是使用 Electron 打包, 既然如此为什么不顺便为 Linux 也提供支持呢 ?) - 2021-04-26更新:后知后觉 deepin 商店已经有 wine 版本的飞书了,详情可看这个 deepin官方帖子 如果公司使用的并不是自己部署版本的飞书的话,可以尝试一下,ubuntu 上面可以再加一个 d...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值