PracHub
QuestionsLearningGuidesInterview Prep

Quick Overview

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.

  • medium
  • Meta
  • Coding & Algorithms
  • Data Engineer

Solve four algorithmic library problems

Company: Meta

Role: Data Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Solve the following coding tasks: 1) Maximum Points from Different Categories: Given an array of items (category, points) and an integer k, choose exactly k items with all categories distinct to maximize the total points. Return the maximum achievable sum. 2) Library Location Management: Design a data structure to manage book locations in a library. Support add(book_id, location), move(book_id, new_location), remove(book_id), and get_location(book_id) in efficient time, where location may include branch, aisle, shelf, and position. 3) Book Checkout Log Validation: Given a chronological list of events (timestamp, book_id, member_id, action in {checkout, return, renew}), validate the log. A book cannot be held by multiple members simultaneously; returns must follow a checkout; renewals only by the current holder; and timestamps for the same book must be non-decreasing. Return a boolean and, if invalid, the index of the first violating event. 4) Two String Validation (no Counter): Given two lowercase strings s and t, determine whether they are anagrams of each other using only basic data structures (e.g., arrays or dicts) and without using collections.Counter. Return true or false.

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

You are given a list of items, where each item is represented as [category, points]. Choose exactly k items such that no two chosen items have the same category. Return the maximum possible total points. If it is impossible to choose k items with distinct categories, return -1. If k is 0, choose no items and return 0.

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

  1. For each category, only the item with the maximum points can ever be useful.
  2. After reducing to one best value per category, the task becomes choosing the k largest values.

Part 2: Library Location Management

Design a simple library location manager. The system stores the current location of each book. Process a sequence of operations: add a new book location, move an existing book, remove a book, or get a book's current location. A location is represented as an opaque string, such as 'Main:A1:S3:P5', which may encode branch, aisle, shelf, and position.

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

  1. A hash map from book_id to location gives efficient add, move, remove, and lookup.
  2. Decide clear behavior for duplicate adds and operations on missing books before coding.

Part 3: Book Checkout Log Validation

You are given a list of library checkout log events in input order. Each event contains a timestamp, book_id, member_id, and an action in {'checkout', 'return', 'renew'}. Validate the log and identify the first invalid event. A book cannot be checked out by multiple members simultaneously. A return must be made by the current holder. A renewal must be made by the current holder. For each individual book, timestamps must be non-decreasing across that book's events. Equal timestamps are allowed.

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

  1. Track the current holder of each checked-out book.
  2. Track the last timestamp seen for each book before validating the action.

Part 4: Two String Validation Without Counter

Given two lowercase strings s and t, determine whether they are anagrams of each other. Two strings are anagrams if they contain exactly the same characters with exactly the same frequencies, possibly in a different order. You may not use collections.Counter or any equivalent built-in frequency 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

  1. If the strings have different lengths, they cannot be anagrams.
  2. A fixed-size array of 26 counts is enough for lowercase English letters.
Last updated: Jun 25, 2026

Loading coding console...

PracHub

Master your tech interviews with 9,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Choose the Cheapest Round Trip - Meta (medium)
  • Palindrome After Deleting at Most One Character - Meta (medium)
  • Validate Sorted Order Under a Custom Alphabet - Meta (medium)
  • Find Shortest Unique Prefixes - Meta (medium)
  • Compute Exclusive Execution Times - Meta (medium)