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.

Basically, this is a combinatorics problem combined with dynamic programming.

So, compute the delta=sum(MAX)-sum(MIN) for all k subsets that can be made and the smallest one is the solution.

Because the array/list is circular, the maximum number of elements that can be used in a subset with the last element from the list is n-k, so I used another list b that generates all list that can be made.

Below is the brute-force approach, but using dynamic programming the complexity can be improved considerably. That is, if a split has been already computed, then there is no need to do it again, instead, first time must be recorded in a table.

Anyway, the complexity of the brute-force solution below is ~O(k*2^n).

Plus, if the table is implemented as a self-balancing binary tree(i.e. red-black tree), then the lookup is improved to logarithmic.

- p.andrey January 11, 2019