Apress.Coding.Interviews.Questions.Analysis.and.Solutions.2012

所需积分/C币:10 2013-06-07 17:30:05 1.62MB PDF
收藏 收藏
举报

Apress.Coding.Interviews.Questions.Analysis.and.Solutions.2012
Contents at a Glance Contents About the author XIII Acknowledgments .mammamammmmamnammmaaaamammmaammmmmmama XV Introduction mmmm xvi CHAPTeR 1- Interview process CHAPTER2: Programming Languages,,…,,…,,…,,…13 CHAPTER 3: Data Structures ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 33 CHAPTER4: Algorithms…,… 75 CHAPTER 5: High Quality code ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ CHAPTER6: Approaches to Solutions.,…,,,,…,…143 CHAPTER 7: Optimization ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■置■■■■■ 187 CHAPTER 8: skillls for interviews 219 CHAPTER 9: Index mmm 275 Introduction i used to be one of those who searched through the internet to prepare for interviews of well-known companies. The information was scattered over lots of web sites, and it was not an easy task to collect coding interview problems and solutions systematically In order to facilitate my own interview preparation, as well as others', i began to write blogs about programming problems and their solutions fter I wrote dozens of blogs, I found that there were common strategies to solve various coding interview problems. Therefore, I gradually realized that it might be a good idea to summarize the strategies in a book With one-year of writing and revising, as well many friends'encouragement and help, now this book is in your hands or perhaps on your screen Distinguishing Features This book analyzes coding problems from interviewers perspectives. There are many tips about the expected behaviors in this book, which are based on my own experiences as an interviewer at Autodesk, Microsoft, and Cisco. Moreover, many interview questions have different solutions. This book evaluates various solutions from an interviewer's point of view. When you read the problem analyses, you will get the idea as to why some solutions are better than others, and you will grasp the capabilities required to the assure the quality of your code through completeness, robustness, and efficiency This book not only solves more than 100 interview problems, but also summarizes common strategies to conquer complex problems. When i analyzed and solved dozens of coding interview problems, I found that there are many general strategies that are quite helpful to solve other similar problems during interviews For example, if an interview problem is quite complex, we may divide it into several small subproblems, and then solve the subproblems recursively We can also utilize hash tables implemented with arrays to solve many interview problems about strings. Similar problems are grouped in sections in this book. Pay attention to the similarities among problems in a section and the general ideas to solve them. When you meet new but similar problems at your interviews, you may reapply the strategies illustrated in this book coding interview is the most important phase of the whole interview process in many companies, such ag Sample questions in this book are real interview problems frequently met in the famous IT'companies The Facebook, Google, and Microsoft. The sample questions collected in this book are the most typical ones adopted by interviewers in these companies. Don 't be discouraged when you find that the problems in this book are not easy because interviews in big companies are not easy for most software engineers at first. You will find that there are relatively few problems that truly test the capabilities of programmers in meaningful ways.So, while you may not get a problem directly from this book, you should attain the skills required to handle whatever an interviewer can dish out. When you gradually master the strategies to solve problems summarized in this book, your capabilities to develop code and solve complex problems will be improved, and you will feel confident when interviewed by the Facebooks and Googles of the world ■| NTRODUCT0N Source code to solve sample interview problems along with a complete set of test cases to each problem is included. After candidates finish writing code, many interviewers will ask them to design some test cases to test their own code. Some candidates, especially fresh graduates, do not have clear ideas about how to design test cases. When you finish reading this book, you should know how to improve code quality with functional test cases, boundary test cases, performance test cases, and so on Summary of chapters The first chapter focuses on the interview process. a typical interview process can be divided into two phases phone interviews (including phone-screen interviews)and on-site interviews. Usually there are three steps in each round of interview, which are the behavioral interview, technical interview, and general Q/A. tips are provided for each stage of interviews The next three chapters cover basic programming knowledge. Technical interview questions on four popular programming languages(C, C++, Ctf, and Java) are discussed in Chapter 2. The most common data structures(including arrays, strings, lists, trees, stacks, and queues)and algorithms (including search, sort, backtracking, dynamic programming, greedy algorithms, and bit operations) are discussed in Chapter 3 and Chapter 4 respectively. Chapter 5 discusses three factors of high quality code Interviewers usually expect candidates'code to fulfill the functional requirements as well as cover corner cases and handle invalid inputs gracefully. After reading this chapter, you should get the idea so that you will write clear, complete, and robust code Three strategies to solve difficult coding interview problems are provided in Chapter 6. If hard problems are met during interviews, candidates should figure out solutions before they write code. After reading this chapter, you may get three strategies to solve problems: figures to visualize problems, step-by-step analysis on examples to simplify problems, and divide-and-conquer strategies to break complex problems into manageable pieces a. The topic of chapter 7 is performance optimization. If there are multiple solutions to a problem, usually interviewers expect the most efficient one. The strategies to improve time efficiency and make trade-off decisions between time and space are discussed with several sample coding interview questions Chapter 8 summarizes various skills for interviews. Interviewers usually pay close attention to candidates communication and learning skills. Additionally, many interviewers like to examine candidates skills of reapplying knowledge, mathematical modeling, and divergent thinking Chapter 9 closes this book with two interview cases, which highlight good behavior expected by interviewers and the most common mistakes made by candidates Downloading the Code ThecodefortheexamplesshowninthisbookisavailableontheApresswebsite,www.apress.com.alink can be found on the book's information page under the Source Code/Downloads tab. This tab is located underneath the Related Titles section of the page XV CHAPTER 1 Interview Process Applying for a technical job is, in many ways, a unique experience. The interview process is unlike other. applicants who do not know what to expect are at a severe disadvantage The purpose of th hy chapter is to acquaint you with the process so that, instead of being surprised, you will have an advantage over your competition. By understanding the process, you will be prepared for even the toughest interviews and have the opportunity to let your talents dictate your success Types of Interviews site interviews. A typical interview process is shown in Figure 5, a phone interview is the first step It is often a long journey before a candidate receives an offer. Typically in the process. If it goes smoothly, a candidate may receive an in on for one or more rounds of on Phone interview On-site Interview Figure 1-1. The interview process Phone interviews During the phone-interview phase, interviewers examine candidates via phone calls. Many interviewers discuss time frames with candidates and schedule a specific time for the interview in advance, but others do not. In some areas of the world, such as India, it is even possible for a candidate to receive an unexpected phone call and be expected to perform an interview at that moment Whether the interview comes at an expected time or not, it is a good practice to find a comfortable and quiet place to take the call. The place should be free of distractions so that the candidate and interviewer can hear each other Compared to on-site interviews, during the phone interview the two sides on the phone can only communicate via voice. It is more difficult for candidates to describe their ideas without auxiliary tools, including body language and facial expressions, especially when describing complex data structures and agorithms. For example, it is quite easy for a candidate to describe a binary tree during an on-site interview because he or she can draw it on paper. However, interviewees on the phone can express clear idea about a binary tree only after describing the binary tree itself in detail, including what the left child and right child of each node are. This kind of explanation can make for an awkward interview or perhaps make it bog down in unnecessary detail CHAPTER 1 INTERVIEW PROCESS Sometimes voices are not very clear over phones. If candidates cannot hear interviewers questions or requirements clearly, they should feel free to ask the interviewers to clarify Providing answers irrelevant to the question should be avoided. Actually asking for more clarification is a good way for candidates to show their communication skills. In some cases, it can also buy time to think of a good response During real software development, requirements are usually ambiguous at first, and engineers have to ask end users for clarification. Therefore, the skill of asking for clarification is an important component of the communication skills set an employer is likely to appreciate Tip Candidates should communicate their thoughts in sufficient detail during phone interviews so that they are convinced interviewers understand their responses Phone-Screen Interviews To facilitate phone interviews, many companies utilize online word-processing tools, such as Google Docs and Collabedit, which allow candidates to easily share and collaborate with interviewers in rea time. Even though the two parties participating in the interview do not physically sit together, interviewers can examine how candidates write code on their desktop screens. an interview that occurs on the phone and uses these word-processing tools is often referred to as a phone-screen interview look Interviewers pay a lot of attention to candidates' programming skills and habits. In most cases,they ok for the following programming habits Thinking carefully before programming It is not usually a good idea for a candidate to begin coding hastily once he or she hears an interview question Without reflecting on the process, a candidate will be prone to write buggy code Remember that the interview situation puts more pressure on the candidates than they feel when they are doing their day-to-day work. Candidates usually are fearful, and sometimes panic, when their bugs are pointed out by interviewers. If they have answered in too much haste, their code might be modified to create an even bigger mess in such situations. A much better strategy for candidates is to implement code after they have clear ideas about their solutions, including data structures and algorithms to utilize, time and space efficiencies, cases requiring error handling, and so on. generally the interviewer will respect the thoughtfulness taken to arrive at the best result. Readable naming convention and indentation Meaningful names of variables and functions as well as clear, logical indentation improve code readability dramatically, and they help interviewers to read and understand code. They also help if you have to debug your code as it will be read more simply More advanced collaboration tools are used in some interviews, such as Microsoft Lync and Cisco WebEx Candidates share their desktops with remote interviewers to show their programming and debugging processes in an IDE, such as Visual Studio or Eclipse What interviewers usually require is an ability to develop a function in order to solve a certain problem. Candidates demonstrate their professional developing skills if they write unit test cases immediately after they finish implementing functions. It is a good practice for a candidate to ask his or her interviewer to review code only after all unit tests pass. It is more impressive if a candidate writes test cases before functional code since test-driven developers are somewhat rare CHAPTER 1 INTERVIEW PROCESS It is quite common for candidates to meet difficult issues during a coding interview. Interviewers pay a lot of attention to candidates behaviors when the candidates realize that their results are not as expected. Interviewers will believe candidates have abundant development experience if they can fix issues in a short time period by scrutinizing the code, setting break points, tracing each step, viewing memory, and analyzing call stacks. Debugging skills are accumulated by lots of practice rather than reading books, so interviewers look for them as a way of ferreting out professional developers On-Site interviews If a candidate performs well during a phone interview, it is quite possible for him or her to receive an invitation for an on-site interview a day or two before the on-site interview, a candidate should consider the following items Scheduling. Candidates need to plan how they will get to the interview, estimate how much time is needed, and leave about half an hour or more for unexpected situations such as traffic jams Wearing comfortable clothes. The dress code in most IT companies is quite casual so usually it is not necessary for engineer candidates to be formally dressed. They can choose whatever is comfortable within reason Paying attention to the interview process. On-site interviews often contain severa rounds. For example, there are usually five rounds of on-site technical interviews for Microsoft. It is quite common to feel fatigued after long interviews. Candidates may wish to bring some vitalizing drinks or food Asking a few questions. Interviewers generally leave a few minutes for candidates to ask some questions before a round of interview ends. Candidates would be wise to prepare some questions in advance On-site interviews are the most important part of the whole interview process because interviewers examine candidates programming skills as well as their communication skills, learning skills, and so on We will cover these skills in the following chapters Phases of interviews Each round of interview is usually split into three phases, as shown in Figure 1-2. The first phase is the behavioral interview, in which interviewers examine candidates experience while referring to their resumes. The second phase is the technical interview when it is highly possible for a candidate to he asked to solve some coding interview problems. Finally, the candidate is given time to ask a few questions Behavioral Technica Q/A Time Interview Interview Figure 1-2. Three phases of a round ofintervieu CHAPTER 1 INTERVIEW PROCESS Behavior interview The first five to ten minutes of a round of interview is used for becoming acquainted. Usually, this is time for the behavioral interview, and no difficult technical questions are asked Interviewers look for someone who would be a good fit for the job in terms of technical skills as well as personality. A person who is too timid might not fit well into an environment where he or she needs to be vocal Interviewers lso look for enthusiasm and excitement. If candidates are not excited about the position they may not be motivated to contribute, even if they are a strong technical fit. Most interviews begin with candidates introducing themselves. A candidate usually doesnt need t spend a lot of time introducing his or her main study and work experiences because interviewers have seen his or her resume which contains detailed information However if an interviewer feels interested in a project the candidate has worked on, he or she may ask several questions on that subject in the Introductory phase. Project Experience After a candidate has introduced him-or herself, interviewers may follow up with some questions on interesting projects listed on his or her resume. It is recommended to use the star pattern to describe each project both on your resume and during interviews(Figure 1-3) Situation: Concise information about the project background, including the size, features, and target customers of the project Task Concrete tasks should be listed when describing a big project. Please notice he difference between"taking part in a project"and"taking charge of a project When candidates mentioned they have taken charge of a project, it is highly possible for them to be asked about the overall architectural design, core lgorithms, and team collaboration. These questions would be very difficult to answer if the candidates only joined a team and wrote dozens of lines of code Candidates should be honest during interviews. Reference checks will also query claims made on resume Action Detailed information should be covered about how to finish tasks if the task was architectural design, what were the requirements and how were they fulfilled? If the task was to implement a feature, what technologies were applied on which platforms Ifit was to test was it tested automatically or manually with black boxes or white boxes Result: Data, especially numbers, about your contribution should be listed explicitly If the task is to implement features, how many features have been delivered in time? If the task is to maintain an existing system, how many bugs have been fixed? 4 CHAPTER 1 INTERVIEW PROCESS Situation Action Result What was What were What actions What was the project the tasks were background?assigned? taken? contribution? Figure 1-3. A STAR pattern describes project experiences on resumes and during interviews Let's look at an example of the star patter in use. i usually describe my experience working on the Microsoft Winforms team in the following terms Winforms is a mature UI platform in Microsoft. NET (Situation I mainly focused on maintenance and on implementing a few new features(Task). For the new features, I implemented new UI styles on Winforms controls in C# in order to make them look consistent between Windows xp and windows 7.I tried to debug most of the reproducible issues we had with Visual Studio and employed winDbg to analyze dump files(Action). I fixed more than 200 bugs in those two years(result Interviewers may follow up with a few questions if the information you supplied in these four ategories has not been described clearly. Additionally, interviewers are also interested in the candidates'answers to the following questions What was the most difficult issue in the project? How did you solve it? What did you learn from the project? hen did you conflict with other team members(developers testers, UI designers, or project managers)? How did you eliminate these conflicts? It is strongly recommended that candidates prepare answers to each of the questions above when they write their resumes. The more time they spend preparing the more confident they will be during interviews Tip When describing a project either on a resume or during an interview, candidates should be concise regarding project background, but they should provide detailed information about their own tasks, actions, and contributions Technical skills Besides project experiences, technical skills are also a key element that interviewers pay close attention to on candidates'resumes. Candidates should be honest in describing the proficiency level of their skills Only when candidates feel confident that they are capable of solving most of the problems in a certain domain, should they declare themselves experts Interviewers have higher expectation of candidates who claim to be experts and ask them more difficult questions. It is very disappointing when you cannot meet these expectations

...展开详情
试读 127P Apress.Coding.Interviews.Questions.Analysis.and.Solutions.2012
立即下载 低至0.43元/次 身份认证VIP会员低至7折
    抢沙发
    一个资源只可评论一次,评论内容不能少于5个字
    关注 私信 TA的资源
    上传资源赚积分,得勋章
    最新推荐
    Apress.Coding.Interviews.Questions.Analysis.and.Solutions.2012 10积分/C币 立即下载
    1/127
    Apress.Coding.Interviews.Questions.Analysis.and.Solutions.2012第1页
    Apress.Coding.Interviews.Questions.Analysis.and.Solutions.2012第2页
    Apress.Coding.Interviews.Questions.Analysis.and.Solutions.2012第3页
    Apress.Coding.Interviews.Questions.Analysis.and.Solutions.2012第4页
    Apress.Coding.Interviews.Questions.Analysis.and.Solutions.2012第5页
    Apress.Coding.Interviews.Questions.Analysis.and.Solutions.2012第6页
    Apress.Coding.Interviews.Questions.Analysis.and.Solutions.2012第7页
    Apress.Coding.Interviews.Questions.Analysis.and.Solutions.2012第8页
    Apress.Coding.Interviews.Questions.Analysis.and.Solutions.2012第9页
    Apress.Coding.Interviews.Questions.Analysis.and.Solutions.2012第10页
    Apress.Coding.Interviews.Questions.Analysis.and.Solutions.2012第11页
    Apress.Coding.Interviews.Questions.Analysis.and.Solutions.2012第12页
    Apress.Coding.Interviews.Questions.Analysis.and.Solutions.2012第13页
    Apress.Coding.Interviews.Questions.Analysis.and.Solutions.2012第14页
    Apress.Coding.Interviews.Questions.Analysis.and.Solutions.2012第15页
    Apress.Coding.Interviews.Questions.Analysis.and.Solutions.2012第16页
    Apress.Coding.Interviews.Questions.Analysis.and.Solutions.2012第17页
    Apress.Coding.Interviews.Questions.Analysis.and.Solutions.2012第18页
    Apress.Coding.Interviews.Questions.Analysis.and.Solutions.2012第19页
    Apress.Coding.Interviews.Questions.Analysis.and.Solutions.2012第20页

    试读已结束,剩余107页未读...

    10积分/C币 立即下载 >