Cracking the coding interview latest edition

Cracking the coding interview latest edition

Interview question!!!

How this book is

We have grouped the interview questions into categories, with one page before each category.

offer advice and other information. Please note that there may be many questions about multi-chat.


Within each category, the questions are ordered by approximate level of difficulty. Solutions

because all questions cracking the coding interview latest edition are left behind.

Special Tips for Software Design Engineers in Test (SDET)

SDETs must not only master testing, they must also be excellent coders. So we recommend

carry out the following preparation process:

»Prepare key test problems: for example, how would you test a light bulb? TO.

pen? Cash register? Microsoft Word? The test chapter will give you more support €

the basis of these problems.

»Practice coding questions: The first thing SDETs reject is coding skills.

Be sure to prepare for the same coding and algorithm questions that are

the developer would get lar.

»Test coding query practice: a very popular format for an SDET query

So even when the question

Unless you specifically ask, you must ask yourself, "How would you test this?" Re¬

member: any problem can be a SDET problem!

Complete and compiled solutions

For your convenience, you can download complete solutions to problems at http: // www. This file provides executable code for all Java files.

solutions. Solutions can be opened and run with Eclipse.

Suggestions and corrections

While we do our best to ensure that all solutions are correct, mistakes will be made. More¬

there, sometimes there is no "correct" answer. If you want to offer a suggestion or correction,

Arrays and strings

Hash tables

While not all problems can be solved with hash tables, there are a large number of interviews

slogans can be. Before your interview, be sure to practice and use

hash tables.

1 Public HashMapcInteger, Student> buildMap (Student [] student) {

3 for (Student: students) map.put (s.getld () j s);

4 rear maps;


An ArrayList, or dynamically resizing array, is an array that resizes as needed

still providing 0 (1) access. A typical application is when a vector is full, the matrix

twice the size. Each duplication takes 0 (n) time, but this rarely happens when time is wasted.

still 0 (1).

Merge 1 public ArrayList <String> (String [] word, String [] plus) {

2 ArrayList <String> statement = new ArrayList <String> ();

3 for (String w: words) statement.add (w);

4 for (String w: plus) sentence.add (w);

5 sentences back;


StringBuffer / StringBuilder

Question: What is the current time of this code?

1 Make a public StringSentence (String [] word) {

2 sentences StringBuffer = new StringBuffer ();

3 for (String w: words) phrase.append (w);

4 return sentences.toString ();


Answer: 0 (n A 2), where n is the number of letters in a sentence. Here's why: every time

add a string to the sentence, create a copy of your sentence and check all the letters in

prayer to copy them. If you have to repeat their characters every time

loop, and if it bends at least n times, that gives you the current time 0 (n A 2). Oh!

1 Make a public StringSentence (String [] word) {

2 sentences StringBuffer = new StringBufferQ;

3 for (String w: words) phrase.append (w);

4 return sentences.toString ();