"Ask questions. Many ignore this question; ask questions to clarify them. Enough

Interviewers deliberately ask vague questions to see if it clarifies their assumptions.

»Wherever possible, design and use data structures. Show that you understand and care

about object-oriented design.

»Think about the data structures you design to represent a line. There is a lot of that

options, cracking the coding interview: 189 programming questions and solutions 6th edition with many commercial dividends. Pick one and explain your choice.

»Do not assume the slope and y-intercept are whole numbers.

»Understand the limits of floating representations. Never check for equality with

Understanding what each operation does (minus, sometimes, segmentation) makes this a potential issue

logically connect.

»The subtraction should be relatively simple, since we all know that a - b is the same

something like a + (-1) * b.

»Multiplication: we have to go back to what we learned in elementary school: 21 * 3 = 21 +21

+21. It is slow, but it works.

»Division is the most difficult, as we tend to think of 3/21 as" if you share

a 21 foot board in 3 pieces, how big is each piece? "If we think about it backwards

around, it's a little easier: "divide a 21 foot board into x pieces and get 3 foot pieces

one, how many pieces were there?

tract 3 feet from 21 feet, we will know how many pieces there are. I mean, we are persistent

»A logical approach to return to direct multiplication and division

I practice. Remember it. All the (good) interview problems can be approached logically.

method lime, methodical!

»The interviewer is looking for this kind of logical approach of working his way.

»Demonstrating your ability to write clean code is a big deal, specifically

to show your ability to reuse code.

use multiple times.

»Be careful to make assumptions when coding. Don't assume that the numbers

If we draw a line between the two points, we can verify which line is

Mon. It would be a brute force approach to just mimic each (formed) line segment

by pairs of dots) and count how many dots fall on it. This would take 0 (N A 3) time.

Before we discuss whether we can do better, let's find out how we can draw a line. A line can

expressed in (at least) two different ways: (1) as a pair of points or (2) as a slope and

an interception and.

Because our line is infinite, the slope and intercept approach seems more appropriate.

The slope and intercept approach and has an additional advantage: all line segments in the

the largest line will have slopes and interception and equals.

Let's reconsider our solution. We have a handful of line segments, expressed as slope and

trouble. We just mimic the line segments and use a hash table to count the number

the times we saw each line.

Be careful when calculating the slope of the line. The line could be full

vertical. We can keep track of this in a separate blanket (infinite_slope). We have to check

this condition in the identical mode.

»Remember that when we divide to calculate slope, the partition is not accurate.

Therefore, instead of checking if two slopes are exactly equal, we should check

if they differ by more than epsilon.