前端面试的作品示例_如何回答任何技术面试问题-包括示例
前端面试的作品示例
Technical interviews can be extremely daunting. From the beginning of each question to the end, it's important to know what to expect, and to be aware of the areas you might be asked about.
技术面试可能会非常艰巨。 从每个问题的开始到结束,重要的是要知道期望什么,并要知道可能会问到的领域。
Fortunately, there's a way to prepare for any question that may come your way. It involves four parts:
幸运的是,有一种方法可以解决您可能遇到的任何问题。 它包括四个部分:
Understand the question
了解问题
Discuss tradeoffs of solutions
讨论解决方案的权衡
Write the code
编写代码
Test the code
测试代码
Let's try this technique with sample problem involving LinkedLists.
让我们尝试这种技术,解决涉及LinkedLists的示例问题。
问题 (The Problem)
Question: Given two singly LinkedListNodes, determine if the two lists intersect. Return the intersecting node. Note that the intersection is defined based on reference, not value. If the kth node of the first linked list is the exact same node (by reference) as the jth node of the second linked list, they are intersecting.
问题:给定两个单独的LinkedListNodes,请确定两个列表是否相交。 返回相交的节点。 请注意,交点是根据参考而不是值定义的。 如果第一个链表的第k个节点与第二个链表的第j个节点完全相同(通过引用),则它们是相交的。
步骤1:了解问题。 (Step 1: Understand the question.)
It's really important to know exactly what this question is asking. Some questions we could ask the interviewer are:
确切知道这个问题在问什么是非常重要的。 我们可能会问面试官的一些问题是:
What exactly do we want to return? (A: The intersecting node).
我们到底要返回什么? (A:相交的节点)。
Does that mean we can assume the linked lists always intersect? (A: Yes)
这是否意味着我们可以假定链表始终相交? (A:是的)
It's always important to gain a sense of the question before thinking about the approach to solving.
在考虑解决方法之前,先要有一个问题的意识总是很重要的。
步骤2:讨论不同解决方案的权衡。 (Step 2: Discuss the tradeoffs of different solutions.)
One immediate solution is to traverse both linked lists at the same time until you reach an intersection. For this example, we would make a pointer at nodes 2 and 7, and traverse each of them one-by-one until we reach a common node.
一种直接的解决方案是同时遍历两个链表,直到到达相交处。 对于此示例,我们将在节点2和7上创建一个指针 ,并逐个遍历它们,直到到达一个公共节点。
However, as you may have noticed, this will not work as the lengths of the two LinkedLists may differ. What we want to do essentially is “chop off” the beginning part of the longer LinkedListNode, and then iterate repeatedly.
但是,您可能已经注意到,这将不起作用,因为两个LinkedList的长度可能不同。 我们实质上要做的是“切掉”较长的LinkedListNode的开始部分,然后重复进行迭代。
This would be the kind of conversation to have with your interviewer.
这将是与面试官进行的对话。
步骤3:编写代码。 (Step 3: Write the code.)
Below is the method to achieve this.
下面是实现此目的的方法。
We make use of helper methods here. We use getKthNode()
to get the kth node of the given linked list. This is helpful when traversing the longer linked list to “chop off” extra nodes.
我们在这里使用辅助方法 。 我们使用getKthNode()
获取给定链表的第k个节点。 当遍历较长的链表以“斩断”多余的节点时,这很有用。
We also use getTailAndSize()
which captures both the length and the last node of the given list. This is helpful because we definitely need the size to compare lengths of the lists. We also need the tails because if the tails of the two lists are unequal, then they don’t intersect at all.
我们还使用getTailAndSize()
来捕获长度和给定列表的最后一个节点。 这很有用,因为我们绝对需要大小来比较列表的长度。 我们还需要尾巴,因为如果两个列表的尾巴不相等,那么它们根本不会相交。
Note that when we say “unequal”, we mean that the two nodes do not reference the same object. Even though they may have the same value and look identical, they must reference the same LinkedListNode to count as equal. (You can find more information on this here.)
请注意,当我们说“不相等”时,是指两个节点没有引用相同的对象 。 即使它们可能具有相同的值并且看起来相同,它们也必须引用相同的LinkedListNode进行计数。 (您可以在这里找到更多信息。)
Going back to the question, if we come across the case where the tails are unequal, we return a failed value (null).
回到问题,如果遇到尾巴不相等的情况,我们将返回失败值(空)。
步骤4:测试代码。 (Step 4: Test the code.)
Below are some good test cases we can add. A helpful rule of thumb for test cases is the following:
以下是一些我们可以添加的良好测试用例。 测试用例的有用经验法则如下:
- Empty/null case空/空箱
- Considering options in the middle/beginning/end考虑中间/开头/结尾的选项
- Sizes equal or different大小相等或不同
This strategy doesn't only apply to LinkedList questions – this would work for arrays, Strings, and essentially any other data structure.
这种策略不仅适用于LinkedList问题,而且适用于数组,字符串以及其他任何数据结构。
For this question, our LinkedList tests would be the following:
对于这个问题,我们的LinkedList测试如下:
- Two linked lists which intersect at the beginning/middle/end在开头/中间/结尾相交的两个链表
- Both/one linked list is null (should return null)两者/一个链接列表为空(应该返回空)
- Linked lists are the same/different size链接列表的大小相同/不同
We’re done!
大功告成!
More Questions:
更多问题:
Circular Linked List
通报链表
Reversing a Linked List
反向链接列表
Palindrome Linked List
回文链接列表
Interested in breaking into Computer Science? Eager to expand your knowledge base and learn new things? Enjoy problem solving?
有兴趣进入计算机科学领域吗? 渴望扩展您的知识库并学习新事物吗? 喜欢解决问题吗?
If so, SWEPrep may be the newsletter for you. Subscribe to get fully explained interview prompts commonly given in engineering interviews, from Arrays to Dynamic Programming. Questions come out weekly and are also categorized by subject and difficulty. The above post is a Guest Post from the author, Sameer Khoja.
如果是这样, SWEPrep可能是您的新闻通讯。 订阅以获得从数组到动态编程的工程访谈中通常给出的全面解释的访谈提示。 每周都会提出问题,并按照主题和难度进行分类。 上面的帖子是作者Sameer Khoja的来宾帖子。
Subscribe to get full access to the newsletter. Never miss an update.
订阅以获得对新闻通讯的完全访问权限。 不要错过任何更新。
翻译自: https://www.freecodecamp.org/news/how-to-answer-any-technical-interview-question-with-example/
前端面试的作品示例
相关文章:

$(shell expr $(MAKE_VERSION) \= 3.81) 这里“\”的解释
android/build/core/main.mk $(shell expr $(MAKE_VERSION) \> 3.81) 为什么要加多一个“\”,因为">"会被shell解析为重定向符号,所以需要转义或用引号包围 所以,也可以这样写$(shell expr $(MAKE_VERSION) “>” 3.81)转载于:https:…

iOS应用模块化的思考及落地方案(一)模块的划分及模块化工作流程
1.0 什么是模块化 很多关于重构及设计模式的介绍中,经常提到的几个词语是复用及解耦。 模块化之所以被提出,也更多是为了解决这几个问题。 复用可以减少重复造轮子的情况,很容易理解的是,我们经常使用的github上的第三方框架&a…

Swiper 用法
部分常用API ininialSlide: 2, //起始图片切换的索引位置(起始从0开始,默认为0) autoplay: 3000, //设置自动切换时间,单位毫秒 speed: 1000, //设置滑动速度 continuous: true, //无限循环的图片切换效果 disableScroll: true, /…
node/js 漏洞_6个可用于检查Node.js中漏洞的工具
node/js 漏洞Vulnerabilities can exist in all products. The larger your software grows, the greater the potential for vulnerabilities. 所有产品中都可能存在漏洞。 您的软件增长得越大,潜在的漏洞就越大。 Vulnerabilities create opportunities for expl…

发现一个浏览器很奇怪的问题
浏览器有8个请求状态为pending时,在另一个tab中,请求就发布出去了,一直是stalled。直到pending状态变成了cancled状态。 试了360浏览器(谷歌内核)和chrome浏览器,都是这样。 具体的原因待深究 参考…

wamp配置虚拟主机
因为wampserver的php版本一直是5.x版本;因此转投xmapp用了一段时间; 意外发现wampserver3更新了;php也终于更新到7了; 果断还是决定回到wampserver的怀抱; 然后有意外的发现了wampserver3有了新功能;可以方…

iOS应用模块化的思考及落地方案(二)模块化自动构建工具的使用
1.0 iOS模块化中的问题 前文已经介绍了模块化的流程及一些常见的问题,我们在这里再次总结一下。 在工作中,当我们开始一个新项目的时候,最先考虑的就是模块化工作。 模块化工作的想法是很美好的,可是执行过程中会遇到很多的问题…

aws fargate_我如何在AWS Fargate上部署#100DaysOfCloud Twitter Bot
aws fargateAfter passing my last certification, I asked myself how much time I spent studying cloud computing.通过上一份认证后,我问自己自己花了多少时间研究云计算。 More than 100 days!超过100天! It also made me realize two things:这也…

think in Java 第五章之垃圾回收类型
1.引用计数: 每个对象都含有一个引用计数器,当有引用连接至对象时,引用计数加1,当引用离开作用域或被置为null时,引用计数减1. 缺陷:在对象循环引用时,存在“对象应该被回收,引用计数…
Yii 错误页面处理
【错误页面处理】 訪问一个错误的控制器 訪问一个错误的方法 有些控制器和方法禁止訪问 以上訪问会提示错误信息 404 403 以上错误信息是不方便给外边用户看到的。 1. 安全隐患 2. 用户体验不好 错误信息在site/error这个地方定义的。如今我们要自己定义错误页面来显示我们的错…

设置RGBColor
#define kUIColorFromRGB(rgbValue) [UIColor \colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

自学成才翁_作为一名自学成才的开发者从“我的旅程”中吸取的教训
自学成才翁The path of the self-taught developer is tough and filled with uncertainty. There is no straight line from newbie to career programmer. Because of this, I believe all self-taught developers have a unique story to tell.自学成才的开发者之路艰难而充…

67)vector的begin() end() 和 front() back()的区别 rbegin() rend()
1) 2)v1.begin() 和v1.end() 是作为迭代器v1的 第一个位置 和 最后一个元素的下一个位置。 v1.front() 是v1这个动态数组的第一个元素的值 v1.back()是v1的最后一个元素的值。 3) 4)正向和反向的使…

倒置函数reverse的用法
倒置字符串函数reverse:用于倒置字符串s中的各个字符的位置,如原来字符串中如果初始值为123456,则通过reverse函数可将其倒置为654321,程序如下:#include<stdio.h>#include<string.h>void reverse(char s[…

设置tabbaritem的title的颜色及按钮图片
设置title颜色: [[UITabBarItem appearance] setTitleTextAttributes:{NSForegroundColorAttributeName : kUIColorFromRGB(0xb2151c)} forState:UIControlStateSelected]; 设置按钮图片: UIImage *commonImage [UIImage imageNamed:[NSString strin…
helm部署仓库中没有的包_Kubernetes的Helm软件包管理器简介
helm部署仓库中没有的包Before we dive into the Helm package manager, Im going to explain some key concepts to deploying any application anywhere. Ill also give you a brief introduction to Kubernetes terminology.在深入研究Helm软件包管理器之前 ,我将…

mem 族函数的实现
1.void * memcpy ( void * dest, const void * src, size_t num ); 头文件:#include <string.h>memcpy() 用来复制内存,memcpy() 会复制 src 所指的内存内容的前 num 个字节到 dest 所指的内存地址上。memcpy() 并不关心被复制的数据类型ÿ…

快排递归非递归python_Python递归神经网络终极指南
快排递归非递归pythonRecurrent neural networks are deep learning models that are typically used to solve time series problems. They are used in self-driving cars, high-frequency trading algorithms, and other real-world applications.循环神经网络是深度学习模型…

我的hadoop学习之路
Hadoop实现了一个分布式文件系统(Hadoop Distributed File System),简称HDFS。HDFS有高容错性的特点,并且设计用来部署在低廉的(low-cost)硬件上。 Hadoop的框架最核心的设计就是:HDFS和MapRedu…

日期处理工具类 -【二】
1、返回本周的第一天(周日为每周第一天) 1 /**2 * 返回本周的第一天(周日为每周第一天)3 * return4 */5 public static String getTheFirstDayOfThisWeek(){6 SimpleDateFormat format new SimpleDateFormat("yyyy-MM-dd");7 Calendar cal Calendar.get…

超越对手pdf_如何创建一个超越竞争对手的移动应用
超越对手pdfThe amount of time people spend on their mobile phones has increased over the years, and so has the number of people using mobile devices.多年来,人们在手机上花费的时间增加了,使用移动设备的人数也增加了。 It’s safe to say t…

vue路由对象($route)参数简介
路由对象在使用了 vue-router 的应用中,路由对象会被注入每个组件中,赋值为 this.$route ,并且当路由切换时,路由对象会被更新。 so , 路由对象暴露了以下属性: 1.$route.path 字符串,等于当前路由对象的路…

join......on 后面的and 和where的区别
a.where 是在两个表join完成后,再附上where条件。 b. and 则是在表连接前过滤A表或B表里面哪些记录符合连接条件,同时会兼顾是left join还是right join。即 假如是左连接的话,如果左边表的某条记录不符合连接条件,那么它不…

block的运用
cell的.h文件 typedef void(^ActivityCellBlock)(NSString *str); interface ActivityCell : UITableViewCell property (nonatomic,strong) NSArray *labelAry; property (nonatomic,copy) ActivityCellBlock myBlock; -(void)showCell:(ActivityCellBlock)myBlock; cel…

如何在Ubuntu 20.04上设置Python虚拟环境
I recently got myself a “new” laptop – a Lenovo x270 (yay)! And once again I needed to set up a Python virtual environment. So of course I Googled for a solution, just to find my previously written article on the same topic!我最近给自己买了一台“新”笔记…

getURLParameters - 网址参数
返回包含当前URL参数的对象。 通过适当的正则表达式,使用 String.match() 来获得所有的键值对, Array.reduce() 来映射和组合成一个单一的对象。 将 location.search 作为参数传递给当前 url。 const getURLParameters url >url.match(/([^?&])…

block的使用
#import "ViewController.h" /* 使用Block最大的一个好处就是可以在代码块中随时访问外部变量 比如你在A.class类中的某个方法中声明了一段代码块.你可以在代码块中直接对A.class所拥有的成员变量进行调用,并且,通过一定的条件(__block),还可以随时的修改这…

关于二级菜单的问题
大家在做二级菜单的时候经常会碰到鼠标移出一级菜单,二级菜单瞬间消失,根本不给你机会移到二级菜单上,今天分享下怎样解决这个问题。 ①第一种介绍一种简单粗暴的方法,二级菜单的元素放入一级菜单中。 代码地址:http:h…

python打印换行符_Python换行符以及如何在不使用换行符的情况下进行Python打印
python打印换行符Welcome! The new line character in Python is used to mark the end of a line and the beginning of a new line. Knowing how to use it is essential if you want to print output to the console and work with files.欢迎! Python中的新行字…

tomcat启动后 项目运行缓慢,要几十到几百秒不等 怎么样./startup.sh 运行加快
修改 linux系统中 /usr/local/jdk1.8.0_11/jre/lib/security/java.security 借力 好文章。我们新的Linux系统,部署了多个 Tomca,同时重启后t, 每次都阻塞差不多260秒左右。修改之后总的启动时间下降到6-8秒左右。另外,不确定为什么࿰…