More Optimal Solution: Still this method requires storing the full range of integers, which has high demand for memory ~10G. Another approach is distributed quick select - divide arrays into trunks that fits in memory. Find median of each trunk by in-memory sorting or quick select. Next round ignore all numbers less than minimum median or bigger than maximum median. Divide remaining elements into trunks that fits in memory. This way every round we'd be able to exclude one trunk of numbers and narrow down the search range, until eventually the range is small enough to fit-in memory.

Feel free to email us aonecoding@gmail.com with any questions. Thanks!

SOLUTION:Seems like there are 3 cases: 1. s1 and s2 share no mutual characters. Then there is no way to further minimize the distance. 2. s1 and s2 share a pair of characters on crossed positions, such as 'b' and 'c' in "aabaaac" and "aacaaab". Then swap 'b' and 'c'. 3. s1 and s2 has no crossed pairs but has the same character on different positions. Then swap to align the character.

Our students got hired from G, U, FB, Amazon, LinkedIn, MS and other top-tier companies after weeks of training.

Email us aonecoding@gmail.com with any questions. Thanks!

SOLUTION:KMP will be one way to do it. Another way will be Rolling Hash.Since a byte has only 256 different values, it won't be hard to create rolling hash on it. For problems like searching bit series in a binary file or searching bytes in byte file, rolling hash can be easier than KMP.

A rolling hash (also known as rolling checksum) is a hash function where the input is hashed in a window that moves through the input.

Our students got hired from G, U, FB, Amazon, LinkedIn, MS and other top-tier companies after weeks of training.

Email us aonecoding@gmail.com with any questions. Thanks!

SOLUTION:Two-way BFS, similar to 'WordLadder'. s1Derives and s2Derives are the words reachable by swapping characters in s1 and s2 in any random way. If s1and s2 are anagrams, for sure s1Derives and s2Derives would join at some point. Find out all possible derivatives 'nextLevel' of s1/s2. Then find out all derivatives of words in 'nextLevel'......until the earliest joint of s1Derives and s2Derives occurs. Return the number of levels gone through.

Our members got into G, U, FB, Amazon, LinkedIn, MS and other top-tier companies after weeks of training.

Feel free to email us aonecoding@gmail.com with any questions. Thanks!

SOLUTION:Step 1, have a table to store all the visits sorted by time stamp.orhave a queue to store the visits per second in the past 5 minute.

Follow-up:Have two arrays hits[range] and lastupdated[range].Range = 5 mins = 300 seconds in this case. Any hit within 'range' time from now is valid and should counted.Index of a hit in the two arrays will be timestamp % 300.Store the last updated time of a hit. Later if a query for the hit count arrives with a query timestamp, sum up all the valid hits from array 'hits'. Threshold for valid hits: query time - hit last updated time < 300.

Followup2For writing,Concurrency update becomes an issue. Add write lock for protection. But this may slowdown the machine badly.

Move hit counters onto a distributed system. Have several machines counting together. Assign userIDs to diff hosts.Add LB on top to make sure requests get distributed evenly.Upon reading, sum up counts across all machines. For a read-heavy system, add cache.

Our students got hired from G, U, FB, Amazon, LinkedIn, MS and other top-tier companies after weeks of training.

Email us aonecoding@gmail.com with any questions. Thanks!

class Node:
def __init__(self, ID, parent):
self.ID = ID
self.parentID = parent
self.left = None
self.right = None
#function to identify if given is preorder
'''
Create a stack to store nodes in the current path when traversing.
Push node[i] into stack once node[i] is verified to be valid (valid only when parent of node[i] is in stack.
In preorder a parent must show up earlier than its child)
Whenever stack top is not the parent of node[i], pop until parent of node[i] is at stack top. Push node[i].
If all nodes popped but parent of node[i] still not found, then node[i] is not in preorder sequence.
'''
def isPreorder(nodes):
if not nodes:
return True
st = [nodes[0].ID]
i = 1
while i < len(nodes):
if not st:
return False
if st[-1] is nodes[i].parentID:
st.append(nodes[i].ID)
i += 1
else:
st.pop()
return True

Our students got hired from G, U, FB, Amazon, LinkedIn, MS and other top-tier companies after weeks of training.

Email us aonecoding@gmail.com with any questions. Thanks!

'''This is sexagesimal addition.e.g.Start from the least significant bit (right-hand side).Check if there is a number bigger than the current digit available. If yes,For least significant digit in '15:31', '3' is the next number bigger than '1'. Then there is no carry to bring forward. Stop adding and return the result '15:33'.

If no,For example '14:59', nothing is bigger than '9'. Then update this bit with the min number and proceedto find the number just bigger than the next bit '5'. It's similar to bringing the carry bit forward in an add operation.

When looking for the number bigger than '5', note that this is a sexagesimal number. Therefore although '9' is bigger than '5', but it can't be taken since it's over '6'. So set '5' to the min number '1'.And proceed to the next number '4'.

'4' has a next bigger number '5'. So set it to '5' and the carry stops here.

In this case, if one more player pL joins the game. The new player pL can be placed into

pL can be here as new 1st place 1st place p1 pL can be here tied with 1st place pL can be here as new 2nd place 2nd place p2, p3 pL can be here tied 2nd place ... ... xth place pN pL can be here tied last place pL can be here as new last

So for every rank combination of N people, adding 1 more player creates rowNumber * 2 + 1 ways of ranking. So if we keep track of the row numbers of all previous combinations of ranking, a ranking with R rows is gonna derive into R + 1 more cases (with R + 1 row numbers) plus R more cases (with R row numbers).

SELECT
Department.name,
COUNT(Employee.id)
FROM
Department
LEFT JOIN
Employee ON Department.dept_id = Employee.dept_id
GROUP BY
Department.dept_id,
Department.name
ORDER BY
COUNT(Employee.id) DESC,
Department.name

Step 1 Find the KeyBased on the rotation rules and the piece of decrypted message:Atvt hrqgse, CnikgYour friend, AliceWe get the code251220825122082

1st character 'Y' + 2 is beyond 'Z'. So start back at 'A'.2nd character 'o' + 5 is 't'.3rd character 'u' + 1 is 'v'etc.

The code is probably periodic on 2512208, more precisely, on a rotation of 2512208 since we do not know where the start of the key is, since "Your friend, Alice" is not at the opening of the text.

To find out the first digit in the key,Known the length of key is 7 and number of letters before the signature is N.So the message is encrypted this way:7 digit key | 7 digit key | … | N % 7 of key7 letters | 7 letters | … | N % 7 lettersThe final key period in the message prior to signature is incomplete with (N % 7) digits used.

The remaining part of the key period (7 - N % 7) goes to the signature"Your friend, Alice".So the first complete key period in "Your friend, Alice" starts at position (7 - N % 7).

In the test case give, there are 92 letters before the signature Your friend, Alice. N = 92(7 - N % 7) = 6Therefore the start of key 2512208 is at the 6th index position which is the 8.So the actual key is 8251220,

Step 2 Recover from RotationOnce the key is found, what left is just to rotate the encrypted message back.Assume current letter in the encrypted message is msg[i] and current key digit is key[j],original letter = msg[i] - key[j] (if original letter underflows ‘a’/’A’, start again from ‘z’/‘Z’).

What's Going On

Books

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Resume Review

Most engineers make critical mistakes on their resumes -- we can
fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.