当前位置: 首页 > 编程日记 > 正文

电子白板 矢量 编码_当涉及白板编码采访时,请记住准备

电子白板 矢量 编码

by Andy Tiffany

通过安迪·蒂芙尼(Andy Tiffany)

当涉及白板编码采访时,请记住准备 (When it comes to whiteboard coding interviews, remember to PREP)

PREP is a mnemonic I created to help you remember the steps involved in solving whiteboard coding problems. It stands for Parameters, Return, Example, Pseudocode.

PREP是我创建的助记符,旨在帮助您记住解决白板编码问题所涉及的步骤。 它代表着对于P arameters,R E打开,E xample,P seudocode。

The mnemonic is new, but the underlying technique is battle tested. This is essentially a beginner-friendly version of test-driven development that lends itself well to coding challenges.

助记符是新的,但是基础技术已经过战斗测试。 这本质上是测试驱动开发的初学者友好版本,非常适合编码挑战。

Let’s get right to it and learn PREP through an example problem. We’ll use JavaScript, but this technique works for just about any programming language.

让我们开始吧,并通过示例问题学习PREP。 我们将使用JavaScript,但是该技术几乎适用于任何编程语言。

面试官要求您编写一个函数,该函数接受一个句子并返回最长的单词。 你是做什么? (Your interviewer asks you to write a function that accepts a sentence and returns the longest word. What do you do?)

“ P”代表参数 (“P” is for Parameters)

Most problems involve writing a function. In this step you need to determine what parameters your function should accept. Then you need to give them meaningful names.

大多数问题涉及编写函数。 在此步骤中,您需要确定函数应接受哪些参数。 然后,您需要给他们起有意义的名字。

Keywords like “takes in” or “accepts” in the problem statement will guide you here. If it’s unclear, you can also ask the interviewer for clarification. In your case, the statement “accepts a sentence” tells you that the function should accept a single string parameter.

问题陈述中的诸如“接受”或“接受”之类的关键字将为您提供指导。 如果不清楚,您也可以要求面试官澄清。 在您的情况下,语句“接受句子”告诉您该函数应接受单个字符串参数。

So you’ve determined the type of your parameter. But what should you name it? It might sound simple, but good naming is a crucial programming skill, and it takes practice.

因此,您已经确定了参数的类型 。 但是你应该给它起什么名字呢? 听起来可能很简单,但是良好的命名是一项至关重要的编程技能,需要实践。

You could call yours “sentenceString,” but calling it “sentence” is more concise and still makes it clear we’re dealing with a string.

您可以将其称为“ sentenceString”,但将其称为“ sentence”更为简洁,但仍然清楚地表明我们正在处理字符串。

Since this is your first step, you also need to think of a meaningful name for your function itself. In your case, “longestWord” is both concise and descriptive. Now that you’ve decided this, you can write the shell for your function like this:

因为这是第一步,所以您还需要为函数本身考虑一个有意义的名称。 就您而言,“ longestWord” 既简洁又具有描述性。 现在,您已经决定了这一点,您可以像下面这样为您的函数编写外壳程序:

“ R”代表退货 (“R” is for Return)

What does this function return? Is it a number? A boolean? A string?

此函数返回什么? 是数字吗 一个布尔值? 弦吗?

Remember: the value a function returns is not the same as what it might display in a print/log statement.

请记住:函数返回的值与它在print / log语句中可能显示的值不同。

Once again, you can look at the problem statement for clarification. “Returns the longest word” tells you that you’re returning a word, and you know that words are strings. Let’s make this crystal clear by creating a variable to represent this return value and rigging up your function to return it. Even though you aren’t returning the correct answer yet, you’re set up to return the correct type. You have created a placeholder that will make the next steps easier.

再一次,您可以查看问题说明以进行澄清。 “返回最长的单词”表示您正在返回一个单词,并且您知道单词是字符串。 让我们通过创建一个代表该返回值的变量并装配函数以返回它的方法来使这一水晶变得清晰。 即使您尚未返回正确的答案,也可以将其设置为返回正确的类型。 您已经创建了一个占位符,它将使下一步变得更容易。

以“ E”为例 (“E” is for Example)

Even for expert developers, static code is harder to understand than running code. You want to make your code runnable and “alive” as soon as possible. You can breathe life into your function with an example test invocation.

即使对于专家开发人员,静态代码也比运行代码更难理解。 您希望尽快使代码可运行并“运行”。 通过示例测试调用,您可以为函数注入生命。

You know that if your function accepts the sentence, “I saw a hippopotamus,” it should return the string “hippopotamus” once it’s properly working. But for now, you just want to see your placeholder value from the last step to confirm your code is runnable and setup correctly.

您知道,如果您的函数接受“我看见了河马”这一句子,则在其正常工作后返回字符串“ hippopotamus”。 但是现在,您只希望从最后一步中看到占位符值,以确认代码可运行并正确设置。

最后一个“ P”代表伪代码 (The last “P” is for Pseudocode)

While it’s tempting to just dive in and start coding now, it would be too easy to get caught up in a detail that could distract you from the bigger picture. You need to devise a strategy first, and pseudocoding is just the tactic for this.

尽管现在就开始潜入并开始编写代码很诱人,但是陷入一个细节可能太容易了,而细节可能使您无所适从。 您需要首先设计一个策略,而伪编码只是为此的策略。

Pseudocode is a series of precise statements written in spoken language comments that describe what you need to do.

伪代码是一系列用口语注释编写的精确语句,它们描述了您需要执行的操作。

您已完成PREP。 现在您可以编码了! (You’ve finished PREP. Now you can code!)

The four steps in PREP helped you clearly frame the problem and think about how to solve it. In truth, accurate framing is half the battle. Most interviewers will already be impressed to see your methodical approach. At this point, your goal is to just write code that will make your examples and tests pass. You’ll do this by encoding each of your pseudocode steps.

PREP中的四个步骤可帮助您清楚地解决问题并思考如何解决。 实际上,准确的构架是成功的一半。 大多数面试官都会对您的系统方法印象深刻。 此时,您的目标是只编写使您的示例和测试通过的代码。 您将通过对每个伪代码步骤进行编码来做到这一点。

You know you’ve got a working solution when you can run your code and see the correct output.

您知道可以运行代码并查看正确的输出时,已经有了可行的解决方案。

You’ve made it through the hardest part now. You can breathe a sigh of relief that you’ve at least gotten to a working solution. At this point, there are just two more questions to think about:

您已经完成了最困难的部分。 您至少可以找到可行的解决方案,然后松一口气。 此时,只需要考虑两个问题:

  • Are there any edge cases that would break the code? For example, do you need to take into account sentences that have a period at the end of them? You’ll write more test cases for these edge cases, then fix the code if necessary.

    是否有会破坏代码的边缘情况? 例如,您是否需要考虑结尾处带有句点的句子? 您将为这些极端情况编写更多的测试用例,然后在必要时修复代码。
  • Can you make the code cleaner or more efficient now? You should discuss ideas with the interviewer so that they know your thoughts before risking breaking the solution.

    您现在可以使代码更整洁或更有效吗? 您应该与面试官讨论想法,以使他们在冒险破解解决方案之前了解您的想法。

That’s it! This process might seem overly mechanical at first, but trust me, it will become second nature — much like the steps in learning to drive. Even after programming for more than 12 years, this is still roughly the sequence I follow when I’m problem solving. I’d more likely use a formal testing framework instead of log statements like we did here, but the steps are the same either way.

而已! 这个过程乍一看似乎过于机械化,但是请相信我,它将成为第二自然-就像学习驾驶的步骤一样。 即使经过12年以上的编程,这仍然大致是我解决问题时遵循的顺序。 我更可能使用正式的测试框架来代替日志语句,就像我们在这里所做的那样,但是两种方法的步骤都是相同的。

Now you try it! Here are a few beginner-level problems you can practice with, in roughly ascending order of difficulty:

现在您尝试一下! 您可以按照一些难度从小到大的顺序练习一些初学者级的问题:

  1. Suppose you have an array of string like [ “adios”, “bye”, “ciao” ]. Your task is to write a function called total_characters that accepts such an array as a parameter and returns the summed number of characters across all the strings in the array.

    假设您有一个字符串数组,例如[“ adios”,“ bye”,“ ciao”]。 您的任务是编写一个称为total_characters的函数,该函数接受这样的数组作为参数,并返回数组中所有字符串的字符总数。
  2. Write a function to flip a coin n times that returns the numbers of times a “heads” was flipped.

    编写一个将硬币翻转n次的函数,该函数返回“正面”翻转的次数。
  3. (From Free Code Camp) We’ll pass you an array of two numbers. Return the sum of those two numbers, and all numbers between them. The lowest number will not always come first. Try using PREP to set this up yourself first, but then feel free to confirm your setup and finish solving it here.

    (来自Free Code Camp )我们将为您传递两个数字组成的数组。 返回这两个数字之和,以及它们之间的所有数字。 最低的数字不一定总是排在最前面。 尝试先使用PREP自己进行设置,然后随时确认您的设置并在此处完成解决。

PREP has already helped several First Step Coding learners ace their coding interviews, and I hope it can help you too. Happy coding!

PREP已经帮助一些“ 第一步编码”学习者获得了他们的编码面试机会,我希望它也能为您提供帮助。 编码愉快!

If you liked this, click the ? below so other people will see this here on Medium.

如果喜欢此,请单击“?”。 下面,以便其他人可以在Medium上看到。

翻译自: https://www.freecodecamp.org/news/before-you-code-remember-to-prep-for-your-coding-interview-2ccfb58147db/

电子白板 矢量 编码

相关文章:

机器学习实战笔记(Python实现)-03-朴素贝叶斯

--------------------------------------------------------------------------------------- 本系列文章为《机器学习实战》学习笔记,内容整理自书本,网络以及自己的理解,如有错误欢迎指正。 源码在Python3.5上测试均通过,代码及…

SQLite.swift的简单使用

使用cocoapod 来进行引入 pod ‘SQLite.swift’ // // SQLiteTool.swift // CreateLectureForSwift // // Created by coder on 2019/6/25. // Copyright © 2019 AlexanderYeah. All rights reserved. // import Foundation import SQLite // id let id Expression(“…

Cypress USB开发文档列表(积累中)

CyUSB.chm(pdf) \Cypress\Cypress Suite USB 3.4.7\Driver Cypress CyUSB.sys Programmers Reference 内容: CyUsb.sys、CyUsb.inf 驱动程序介绍,如何绑定设备到驱动程序,以IOCTL Interface、CYIOCTL.Hd的解释为主要内容的编程指导,主…

对象冒充_使用您的精神探照灯进行冒充冒名顶替综合症

对象冒充by Jaime J. Rios由Jaime J. Rios “Stop that imposter! Seize them!”“停止冒名顶替者! 抓住他们!” I first spotted my imposter two years ago. It happened when I began learning how to code.两年前,我第一次发现了冒名顶…

grep 函数

linux grep命令1.作用Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来。grep全称是Global Regular Expression Print,表示全局正则表达式版本,它的使用权限是所有用户。 2.格式gr…

iOS weak 自动置为nil的实现

1 weak 自动置为nil的实现 runtime 维护了一个Weak表,weak_table_t 用于存储指向某一个对象的所有Weak指针。Weak表其实是一个哈希表, key是所指对象的地址,value是weak指针的地址的数组。 在对象回收的时候,就会在weak表中进…

iOS 缓存策略

Github https://github.com/gaosboy/kache https://github.com/swtlovewtt/WTRequestCenter https://github.com/hans007/CacheFile Image https://github.com/youger/UIImageView-ASIImageCache转载于:https://www.cnblogs.com/hl666/p/3931182.html

数据结构的简要介绍:图形如何工作

by Michael Olorunnisola通过Michael Olorunnisola 数据结构的简要介绍:图形如何工作 (A Gentle Introduction to Data Structures: How Graphs Work) So who wants to work at Google, Facebook, or maybe LinkedIn? Beyond their grueling interview process, o…

Catel(翻译)-为什么选择Catel

1. 介绍 这篇文章主要是为了说明,我们为什么要使用Catel框架作为开发WPF,Silverlight,和Windows phone7应用程序的开发框架。 2. 通用功能 2.1. 这是你的选择 针对需对开发者,再使用架构的时候是希望有很大的自由度的,但是大部…

iOS 三种类型的Block

Block 的copy 操作 Block 其实来讲有三种类型 全局块 NSConcreteGlobalBlock 栈块 NSConcreteStackBlock 堆块 NSConcreteMallocBlock 全局块存储在全局内存中,相当于单例 栈块存于栈内存中,超出其作用域则马上进行销毁 堆块存在于堆内存中&#x…

2.4G高频PCB天线设计

2.4G高频PCB天线设计转载于:https://www.cnblogs.com/LittleTiger/p/6215262.html

如何一起破解图形化Python调试器

15分钟内从零调试 (Zero-to-Debugging in 15 mins) You don’t realize the value of a debugger until you’re stuck working on a hard-to-visualize problem. But once you fire up a development environment with decent debugging capabilities, you’ll never look bac…

python 之路,Day11 (下)- sqlalchemy ORM

python 之路,Day11 - sqlalchemy ORM 本节内容 ORM介绍sqlalchemy安装sqlalchemy基本使用多外键关联多对多关系表结构设计作业1. ORM介绍 orm英文全称object relational mapping,就是对象映射关系程序,简单来说我们类似python这种面向对象的程序来说一切…

iOS事件响应链

1 如下 NSObject 显然是基类,都是继承与UIResponder. 可以看出UIApplication,UIView,UIViewController都是继承自UIResponder类,可以响应和处理事件 我们都是通过UIResonder 来查找控件的父视图控件。’ 发生触摸事件之后&…

论5级流水32bit risc cpu设计

前段时间用verilog写了一个32bit的risc cpu,五级流水,下板调试已经完全可用,准备后期加入浮点运算器,因为最近事情超级多,因此暂时先把RTL图传上来供大家参考,后面我会讲具体怎么设计。希望大家多多关注 :)转载于:http…

开源项目贡献者_嘿新手开源贡献者:请写博客。

开源项目贡献者by Shubheksha通过Shubheksha 嘿新手开源贡献者:请写博客。 (Hey newbie open source contributors: please blog more.) As a newbie open source contributor, I often felt lost and dejected. I couldn’t figure out how different modules fit…

instanceof, isinstance,isAssignableFrom的区别

instanceof运算符 只被用于对象引用变量,检查左边的被测试对象 是不是 右边类或接口的 实例化。如果被测对象是null值,则测试结果总是false。 形象地:自身实例或子类实例 instanceof 自身类 返回true 例: String snew String(&qu…

POJ - 3538 - Domestic Networks

先上题目: Domestic NetworksTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 732 Accepted: 204 Special JudgeDescription Alex is a system administrator of Domestic Networks Inc. His network connects apartments and spans over multiple buil…

iOS HitTest 机制

当用户触摸(Touch)屏幕进行交互时,系统首先要找到响应者(Responder)。系统检测到手指触摸(Touch)操作的时候,将Touch 以UIEvent 的方式加入到UIApplication 事件队列中去。UIApplica…

巨石加密_缓解巨石

巨石加密by Ian Belcher伊恩贝尔彻(Ian Belcher) 我们如何将技术堆栈转向基于服务,以开发人员体验为中心的设计 (How we pivoted our tech stack to a service-based, developer experience-focused design) This article documents the problems we experienced w…

Python函数中的参数(一)

函数传递参数时的简要关键点: 1、参数的传递是通过自动将对象赋值给本地变量名来实现的。函数参数在实际中只是Python赋值的一个实例。因为引用是以指针的形式实现的,所有的参数实际上都是通过指针进行传递的。 2、在函数内部的参数名的赋值不会影响调用…

LLDB 调试相关

LLDB 初始 LLDB 是一个有着 REPL 的特性和 C ,Python 插件的开源调试器。LLDB 绑定在 Xcode 内部,存在于主窗口底部的控制台中。调试器允许你在程序运行的特定时暂停它,你可以查看变量的值,执行自定的指令,并且按照你所认为合适的…

javascript优缺点_为什么要在JavaScript中使用静态类型? 优缺点

javascript优缺点by Preethi Kasireddy通过Preethi Kasireddy 为什么要在JavaScript中使用静态类型? 优缺点 (Why use static types in JavaScript? The Advantages and Disadvantages) We covered a lot of ground in Part 1! With syntax out of the way, let’…

大数的减法函数--c语言

代码展示&#xff1a; http://paste.ubuntu.com/23693598/ #include<stdio.h> #include<stdlib.h> #include<string.h> char * largeDiffer(char *a,char *b){ /* 使用说明 传入的a和b只能为整数 结果为a-b;返回的为字符指针&#xff0c;注意数组不要越…

json 基础

json格式 JSON格式&#xff1a;http://www.json.org/ python和JSON的关系请参考&#xff1a;http://docs.python.org/library/json.html JSON建构有两种结构&#xff1a; 1. “名称/值”对的集合&#xff08;A collection of name/value pairs&#xff09;。不同的语言中&#…

iOS 中 load 和 initialize的实现顺序

1 load 函数 调用时机&#xff0c;当类引用进项目的时候执行load函数&#xff0c;在main函数开始之前&#xff0c;与 这个类是否被用到是无关的&#xff0c;每个类的load函数都会自动调用一次。 1 父类和子类都实现load函数的时候&#xff0c;父类的load方法优先于子类 2 类…

需求简报_代码简报:有史以来最怪诞的丑毛衣

需求简报Here are three stories we published this week that are worth your time:这是我们本周发布的三个值得您关注的故事&#xff1a; The geekiest ugly sweater ever: 4 minute read 有史以来最怪异的丑毛衣&#xff1a; 4分钟阅读 Lessons from my post-bootcamp job …

C#内置函数 RunSql的使用

作用批量执行sql语句表达式.RunSQL(SQLStatement,UseTransaction)表达式.一个代表DoCmd对象的变量。注释&#xff1a;sqlstatement参数的最大长度为 32,768 个字符&#xff08;而"宏"窗口中的 SQL 语句操作参数的最大长度为 256 个字符&#xff09;。 官方说仅能用于…

swif 在字符串中查找特定字符索引以及改变字符串的指定位置的颜色 字体大小

1 第一种方式 var text "谁包含这个字母";let range:Range<String.Index> text.range(of: "含")!;let end_idx:Int text.distance(from: text.startIndex, to: range.lowerBound);// 打印2print(end_idx);类方法 抽取 // 查找对应索引static func…

SD卡的控制方法(指令集和控制时序)

1.SD卡的命令格式&#xff1a; SD卡的指令由6字节(Byte)组成&#xff0c;如下&#xff1a; Byte1&#xff1a;0 1 x x x x x x(命令号&#xff0c;由指令标志定义&#xff0c;如CMD39为100111即16进制0x27&#xff0c;那么完整的CMD39第一字节为01100111&#xff0c;即0x270x40…