Implement pagination and clump grouping
Company: Peregrine
Role: Software Engineer
Category: Data Manipulation (SQL/Python)
Difficulty: Medium
Interview Round: Technical Screen
You are given two pre-implemented APIs:
(
1) fetch_activities(page: int) -> { total_pages: int, activities: [ { activity_id: string, type: string, user_id: string, payload: object } ] };
(
2) fetch_user_name(user_id: string) -> string. Perform the following:
- Pagination and print: Call fetch_activities for all pages, obtain the total count, aggregate every activity across pages, and print each activity.
- Group into clumps: Group activities by (type, user_name). Define a class Clump { type: string, name: string, activities: List[Activity] }. Return a list where each group is represented as a Clump, except when a group would contain exactly one activity—in that case return the single Activity object directly instead of a list/Clump.
- Replace IDs with names: When printing, show user_name (fetched via fetch_user_name) instead of user_id. Minimize redundant user lookups (e.g., with caching), and handle API errors, rate limits, and timeouts gracefully.
- Take‑home framing: Briefly describe how you would approach a take‑home variant where you must understand business context first, then aggregate the data, and finally filter results. State assumptions, edge cases, and validation steps.
- Complexity and tests: Provide time/space complexity and outline unit tests, including pagination boundaries, empty pages, missing users, and mixed single-item vs multi-item clumps.
Quick Answer: This question evaluates practical skills in paginated API integration, data aggregation and grouping (clump formation), ID-to-name resolution with caching, error and rate-limit handling, and designing unit tests and complexity analysis within the Data Manipulation (SQL/Python) domain.