前端面试的作品示例_如何回答任何技术面试问题-包括示例

news/2024/7/5 7:08:28

前端面试的作品示例

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:

幸运的是,有一种方法可以解决您可能遇到的任何问题。 它包括四个部分:

  1. Understand the question

    了解问题

  2. Discuss tradeoffs of solutions

    讨论解决方案的权衡

  3. Write the code

    编写代码

  4. 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:

确切知道这个问题在问什么是非常重要的。 我们可能会问面试官的一些问题是:

  1. What exactly do we want to return? (A: The intersecting node).

    我们到底要返回什么? (A:相交的节点)。

  2. 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/

前端面试的作品示例


http://lihuaxi.xjx100.cn/news/237186.html

相关文章

Win10 下 RabbitMQ 的 安装 配置

记录下本人在win10环境下安装RabbitMQ的步骤,以作备忘。 第一步:下载并安装erlang 原因:RabbitMQ服务端代码是使用并发式语言Erlang编写的,安装Rabbit MQ的前提是安装Erlang。下载地址:http://www.erlang.org/download…

智能合约和区块链技术:入门指南

链客,专为开发者而生,有问必答! 此文章来自区块链技术社区,未经允许拒绝转载。 智能合约和区块链技术:入门指南 多年前,在没有数字合约和区块链技术存在的情况下,双方的合约往往以传统的方式进…

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…

什么是网络爬虫,网络爬虫有什么用?

什么是网络爬虫,网络爬虫有什么用? 简单地说,就是把网页所展示数据通过非人工的手段获取下来。 现在是大数据时代,数据分析是解决各行各业相关问题重要的依据。数据分析结果的准确性有很大一部分取决于数据量是否足够大。如果是几…

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:这也…

玉蟾宫

题目链接:https://www.luogu.org/problemnew/show/P4147 题目背景 有一天,小猫rainbow和freda来到了湘西张家界的天门山玉蟾宫,玉蟾宫宫主蓝兔盛情地款待了它们,并赐予它们一片土地。 题目描述 这片土地被分成N*M个格子&#xff0…

EOS技术知识介绍

链客,专为开发者而生,有问必答! 此文章来自区块链技术社区,未经允许拒绝转载。 EOS 简介 EOS:EOS可以理解为Enterprise Operation System,即为商用分布式应用设计的一款区块链操作系统。EOS是EOS软件引入…

自学成才翁_作为一名自学成才的开发者从“我的旅程”中吸取的教训

自学成才翁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.自学成才的开发者之路艰难而充…