Python
Questions 1 and 2 are basically the same as the ones posted yesterday. For question 1, I got a follow-up: how do you write it without heapq. For question 2, the log list's true/false values need to alternate, and you also have to consider that a book needs to be checked out before it can be returned — otherwise that's wrong too.
Question 3 is a new one I'd never seen before and it's a bit convoluted — I still don't fully understand it even now.
They gave a dict like this, representing a company's four buildings and how many people each building can hold:
{"A":{"A":80,"B":10,"C":20,"D":10},
"B":{"A":5, "B":110, "C":5, "D":15},
"C":{"A":5,"B":10,"C":150,"D":5},
"D":{"A": 10, "B":5,"C":10,"D":180}}
They also gave a list, something like {"C","D"} — could also be empty. I don't understand why it's curly braces, but that's what it was.
And this is where I can't help everyone anymore, because I didn't understand what he wanted either. All I can say is you need to return {"A":xx,"B":xx} — meaning if C and D are closed, then A and B need to absorb the extra people from C and D.
If the list is empty, you just return {"A":80,"B":110,"C":150,"D":180} — only taking A's A, B's B, C's C, D's D.
Where I got stuck was the test case where site A is closed — B needs to become 120, not 115. I forget the exact numbers for C and D, but they all need to increase.
SQL
Same 4 tables as yesterday's post — copies, checkouts, members, and books. The question was identical to yesterday's post too, and it felt a lot easier than the earlier bookstore one, which let me win back some time to go back and look at that new Python question. No, no, actually I should say the interviewer was super helpful debugging with me.
-
Need to return two columns. The first is a count of books whose condition is good (I asked, and it needs to be an exact match) that have never been returned. The second column is the percentage of those books where renewal > 2. Possibly relevant columns: copies has copy_id, condition; checkouts has copy_id, return_date. I forget which table renewal is in.
-
This question gave a hint that return_date minus checkout_date gets you the time difference. It's asking for the top three books, among books with copies > 10, with the longest total loan time. Possibly relevant columns: copies has copy_id, book_id; checkouts has copy_id, return_date, and checkout_date.
-
Need the max member_id, referrer_member_id, diff_of_reserved_copy_num. Possibly relevant columns: copies has copy_id, reserved_by_member_id; members has member_id, refered_by_member_id.
I spent the rest of the time going back to look at Python question 3 and didn't get to look at question 4.
Discussion
Loading comments…