Fetch paginated data from two APIs
Company: Armada
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates a candidate's competency in robust API retrieval, pagination handling, defensive data validation, and joining records across endpoints while preserving the order of source records and safely handling missing or malformed fields.
Constraints
- Pages are already supplied in pagination order.
- target_field values that are null, empty, or whitespace-only are skipped.
- For duplicate ref_id rows in API B, the first valid value is used.
Examples
Input: ([{"data":[{"id":1,"ref_id":"x1"},{"id":2,"ref_id":"x2"}],"next_page":2},{"data":[{"id":3,"ref_id":"x3"}],"next_page":None}], [{"data":[{"ref_id":"x1","target_field":"v1"},{"ref_id":"x2","target_field":"v2"}],"next_page":None},{"data":[{"ref_id":"x3","target_field":""}],"next_page":None}])
Expected Output: [{'id': 1, 'target_field': 'v1'}, {'id': 2, 'target_field': 'v2'}]
Explanation: Records are joined in API A order and blank target fields are skipped.
Input: ([{"data":[{"id":1},{"id":2,"ref_id":"z"}]}], [{"data":[{"ref_id":"z","target_field":" ok "}]}])
Expected Output: [{'id': 2, 'target_field': ' ok '}]
Explanation: Missing ref_id rows are skipped safely.
Hints
- Flatten the pages defensively.
- Build a ref_id lookup from API B before scanning API A.