Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created January 7, 2020 19:37
Show Gist options
  • Save jianminchen/d5c7a2f18cc5066edacd7b5a2392e881 to your computer and use it in GitHub Desktop.
Save jianminchen/d5c7a2f18cc5066edacd7b5a2392e881 to your computer and use it in GitHub Desktop.
January 6, 2020 - 8:00 PM - mock interview as an interviewee -
It's Christmas morning!
Each member of the family has some number of gifts to open, which they will do one-at-a-time as a group.
The goal is to put together an ordering for opening presents that is most "fair". To define "fair", we
consider the contiguous intervals in which a person is *not* opening presents, and try to minimize the squared sum
of the length of those intervals.
First, we'll want a function to be able to tell how good our potential solutions are.
1) Implement a scoring function that takes a given order as a list and returns the squared sum of the length
of the intervals in which they are *not* opening presents.
Input: ["Alice", "Bob", "Bob"]
Output: 5 (Alice is not opening for one interval of length two, Bob is not opening for one unit interval, 2^2+1^2 = 5)
Input: ["Bob", "Alice", "Bob"]
Output: 4 (Alice is not opening for two interval of length one, Bob is not opening for one unit interval, 1^2+1^2+1^2 = 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment