How to read cracking the coding interview

How to read cracking the coding interview


Perhaps our first instinct in this problem is to randomly select elements from the array and add

in our new set of subsets. how to read cracking the coding interview But then what happens if we choose the same item twice? Ideally,

we want to somehow "shrink" the array so that element no longer exists. There is contraction

expensive however due to all the transfer required.


from the array and then "remember" that the element now contains only elements j and more.

That is, when we select a subset [0] to be matrix [k], we replace the first element with matrix [k]

matrix. When we select a subset [1], we consider a matrix [0] "dead" and we randomly choose

element and between 1 and array.sizeQ. Then we set a subset [1] equal to the matrix [y], and set]

equal to a series [1]. Items 0 and 1 are now "dead". Now a subset [2] of a matrix [2] is selected

by array [array.size ()], and so on.

It will assume that this question is not related to word order. This is a question for you

You must ask your interviewer a question. If the order of the words is important, we can make minor modifications.

shown in the following code.


To solve this problem, cross the file and for each occurrence of wordl and word2,

compare the difference of the sites and update the current minimum.

To solve this problem in less time (but more space), we can create a hash table with each of them

word and the locations where it appears. So we just need to find the minimum (arithmetic)

position difference (for example, abs (word0.loc [1] - word1.loc [5])).


To find the minimum arithmetic difference, we construct each position for wordl (for example: 0, 3} and

do a modified binary search on the word2 site list, returning the number closest to you. Our

search 3, for example, would return {2,7,9} 1. The minimum of all these binary searches

the shortest length.

Sort the items and then take the first million numbers from there. The complexity is 0 (n log n).

Approach 2: maximum heap


1. Create a minimal pile with the first million numbers.


2. For each remaining number, put it into the minimum heap and then delete the minimum

heap value.


3. The largest million numbers are now on the heap.


Method 3: selection pass algorithm (if you can modify the original set)


Selection in the computer classroom is a popular algorithm for eating less (or

the main feature) edit in the expected linear time. The basic algorithm to get the ate

the smallest elements are like this:


»Select a random function in the matrix and use it as a 'bot'. Move each item less than

that element on one side of the array, and all elements larger than the other.


»If there are elements on the right, then you get only the smallest element

that side.


»Otherwise, if the right side is greater than i, repeat the correct algorithm again. Yeah that's right

the side is smaller than i, repeat the algorithm on the left for i - right.sizeQ.


Given this algorithm, you can:


»Use it to use existing partitions to find the i major elements (i i = thousand¬

Lion).


»Or, when you find the https://crackingthecodinginterview.co/ largest element, rerun the array to return all elements

greater or equal to.


This algorithm waits for time O (n).