Solve four algorithmic library problems
Company: Meta
Role: Data Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: These tasks evaluate algorithmic problem-solving, data structure design, stateful system validation, and string-processing correctness by combining an optimization selection problem, a mutable location-management ADT, chronological event-log validation, and constrained anagram checking.
Part 1: Maximum Points from Different Categories
Constraints
- 0 <= len(items) <= 100000
- 0 <= k <= 100000
- Each category is an integer in the range [-10^9, 10^9]
- Each points value is an integer in the range [-10000, 10000]
- You must choose exactly k items when possible
Examples
Input: ([[1, 10], [2, 5], [1, 7], [3, 8]], 2)
Expected Output: 18
Explanation: The best item from category 1 has 10 points, and category 3 has 8 points. Choosing them gives 18.
Input: ([[4, -5], [4, -2], [5, -3], [6, 10]], 2)
Expected Output: 8
Explanation: The best per category values are -2, -3, and 10. The top 2 sum to 8.
Hints
- For each category, only the item with the maximum points can ever be useful.
- After reducing to one best value per category, the task becomes choosing the k largest values.
Part 2: Library Location Management
Constraints
- 0 <= len(operations) <= 100000
- book_id is a non-empty string
- location is a non-empty string for add and move operations
- All operation names are one of 'add', 'move', 'remove', 'get_location'
- Expected average time per operation should be O(1)
Examples
Input: ([['add', 'B1', 'Main:A1:S1:P1'], ['get_location', 'B1'], ['move', 'B1', 'East:A2:S3:P4'], ['get_location', 'B1']],)
Expected Output: ['added', 'Main:A1:S1:P1', 'moved', 'East:A2:S3:P4']
Explanation: B1 is added, found, moved, and then found at the new location.
Input: ([['add', 'B1', 'L1'], ['add', 'B1', 'L2'], ['get_location', 'B1']],)
Expected Output: ['added', 'exists', 'L1']
Explanation: The second add does not overwrite an existing book.
Hints
- A hash map from book_id to location gives efficient add, move, remove, and lookup.
- Decide clear behavior for duplicate adds and operations on missing books before coding.
Part 3: Book Checkout Log Validation
Constraints
- 0 <= len(events) <= 100000
- timestamp is a decimal string representing an integer in the range [0, 10^12]
- book_id and member_id are non-empty strings
- action is one of 'checkout', 'return', or 'renew'
- Timestamps are checked independently per book, not globally across all books
Examples
Input: ([['1', 'B1', 'M1', 'checkout'], ['2', 'B1', 'M1', 'renew'], ['3', 'B1', 'M1', 'return'], ['4', 'B2', 'M2', 'checkout']],)
Expected Output: [True, -1]
Explanation: All actions are consistent and timestamps for each book are non-decreasing.
Input: ([['1', 'B1', 'M1', 'checkout'], ['2', 'B1', 'M2', 'checkout']],)
Expected Output: [False, 1]
Explanation: B1 is already checked out by M1 when M2 tries to check it out.
Hints
- Track the current holder of each checked-out book.
- Track the last timestamp seen for each book before validating the action.
Part 4: Two String Validation Without Counter
Constraints
- 0 <= len(s), len(t) <= 100000
- s and t contain only lowercase English letters 'a' through 'z'
- Do not use collections.Counter or similar built-in frequency-counting utilities
Examples
Input: ('listen', 'silent')
Expected Output: True
Explanation: Both strings contain the same letters with the same frequencies.
Input: ('rat', 'car')
Expected Output: False
Explanation: The character counts differ.
Hints
- If the strings have different lengths, they cannot be anagrams.
- A fixed-size array of 26 counts is enough for lowercase English letters.