is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
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.
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.
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.
So from my interpretation, an inversion is just anytime a number is greater than any other number in the list regardless of where they are situated in the array. So this gives us the ability to sort the array and not alter the results.
So in my JS implementation in O(nlgn) time:
1. Sort the input array
time: O(nlgn)
2. Keep track of all duplicate values in array. We do this with a JS object (which acts as a set).
-- key = duplicated value
-- value = array of indexes
time: O(n)
3. Starting from the end of the array, we look at its index.
The number of inversions for that number and every other number to the left of it will be equal to:
=it's array index - the number of duplicates of that particular value in question that are to the left
eg. for [1,2,2]
for 2(end value): the number of inversions = 2 - 1 = 1
for 2(middle value): the number of inversions = 1 - 0 = 1
for 1 (first value): the number of inversions = 0 - 0 = 0
time: O(n)
try running this in jsfiddle: jsfiddle.net/ 7v7XN/1/
- theol88 March 10, 2014