During my software engineering career I was able to interview several developers including interns who were looking for a training program and also former engineers/newly graduated university students who were looking for a new position in their career. I thought to share solutions for technical questions that I asked frequently.
在我的软件工程职业生涯中,我采访了一些开发人员,包括正在寻找培训课程的实习生,以及正在寻找职业新职位的前工程师/刚毕业的大学生。 我想分享我经常问到的技术问题的解决方案。
“实用至上”的问题 (“Practical-first” questions)
When it comes to interview questions I would prefer practical questions(based of theoretical knowledge of course) over completely theoretical questions because anyone can answer a fully theoretical problem easily without having in-depth knowledge about the related theorem and without applying bit of a thinking. Following type A,B examples will differentiate it clearly,
当涉及面试问题时,相对于完全理论的问题,我更喜欢实际问题(当然是基于理论知识的问题),因为任何人都可以轻松地回答完全理论的问题,而无需对相关定理有深入的了解,也无需进行任何思考。 遵循A,B类型的示例可以清楚地区分它,
A: What is stack and how it works?
答:什么是堆栈及其工作原理?
B: How would you use stack to find all brackets are properly closed in getItem([[2,3],[10]])
B:您将如何使用堆栈来找到所有在getItem([[2,3],[10]])
中正确括起来的括号
Q1 —上下文问题 (Q1 — The context problem)
Question: Modify the following code and call MainWindow.setIcon
method from TitleBar.changeIcon
method.
问题 :修改以下代码,然后从TitleBar.changeIcon
方法调用MainWindow.setIcon
方法。
class MainWindow {
TitleBar tb;
MainWindow() {
tb = new TitleBar();
}
setIcon() {
}
}
class TitleBar {
changeIcon() {
}
}
Solution: Many applicants asked from me “Can’t we simply create a new instance of MainWindow
”. But the expected approach is to pass the context as per below.
解决方案 :许多申请人向我询问“我们不能简单地创建MainWindow
的新实例”。 但是预期的方法是按照以下方式传递上下文。
class MainWindow {
TitleBar tb;
MainWindow() {
tb = new TitleBar(this);
}
setIcon() {
}
}
class TitleBar {
MainWindow context;
TitleBar(MainWindow ctx) {
context = ctx;
}
changeIcon() {
context.setIcon();
}
}
Q2 — JSON问题 (Q2 — The JSON problem)
Question: Print all values v
from following JSON object.
问题 :从以下JSON对象打印所有值v
。
{
"a":{
"a":{
"v":20,
"b":{
"v":60
}
},
"v":10
},
"b":{
"b":{
"v":70,
"a":{
"v":100
}
},
"v":50
},
"v":12
}
Solution: Some people started with “nested for” loops. But the expected way is to use recursive function (in theory it’s binary tree traversal or knowledge from depth first search — dfs
also can be applied)
解决方案 :有些人从“嵌套”循环开始。 但是预期的方式是使用递归函数(理论上,它是二叉树遍历或深度优先搜索的知识,也可以应用dfs
)
J = {
"a":{
"a":{
"v":20,
"b":{
"v":60
}
},
"v":10
},
"b":{
"b":{
"v":70,
"a":{
"v":100
}
},
"v":50
},
"v":12
};
function visitNode(n) {
if(!n)
return;
console.log(n.v);
visitNode(n.a);
visitNode(n.b)
}
visitNode(J);
Q3 —阶乘问题 (Q3 — The factorial problem)
Question: Write a recursive function to return nth
factorial and explain how it works referring stack frames in computer memory.
问题 :编写一个递归函数以返回nth
阶乘,并解释其如何引用计算机内存中的堆栈帧。
Solution: I used to ask this from students who were going to be interns since this was covered university studies. I wrote a separate article for recursion which can be found here (it has the solution for this question).
解决方案 :我曾经问过要成为实习生的学生,因为这涵盖了大学学习。 我写了另一篇关于递归的文章,可以在这里找到(它有解决这个问题的方法)。
结论 (Conclusion)
Support practical-first type questions and if you an engineer who usually interviews developers please let them know answers for each coding questions eventually since it can be a good learning for their future interviews or for their software engineering career in your company.
支持实用型问题,如果您是一位通常与开发人员面谈的工程师,请最终让他们知道每个编码问题的答案,因为这对于他们将来的面试或您公司的软件工程职业都是很好的学习方法。
Happy coding 😎
快乐编码😎