Implement a Paginated Medical-Record Filter Without Guessing an Ambiguous Rule
OracleSoftware Engineer · Technical ScreenLast updated
This problem tests your ability to handle ambiguous business logic through requirement clarification and implement a robust, paginated filtering system for sensitive data.
The Scenario
You are building a backend service to retrieve patient medical records. You receive a request to filter records by 'Hypertension' status, defined as patients having a recorded systolic blood pressure over 140 mmHg. However, the requirement document is contradictory: it states 'greater than 140' in the text but shows a sample '140 included' in the appendix.
Your Task
- State your assumption regarding the 140 mmHg boundary.
- Implement a function
get_hypertension_records(records, page, page_size).
Input Data
records is a list of dictionaries:
{
'id': int,
'systolic_bp': int,
'patient_dob': 'YYYY-MM-DD'
}
Requirements
- Logic: Filter records where
systolic_bpmatches your clarified boundary. - Pagination: Return a subset of records based on the current page (1-indexed) and page size.
- Ordering: To ensure reproducibility, records must be sorted by
id(ascending) before pagination. - Error Handling: If a record has a null
systolic_bpor malformedpatient_dob, skip the record and log it (simulated by adding to an internalerrorslist). - Output: Return a dictionary containing the paginated list, the total count of matching records, and the current page number.
Example
records = [
{'id': 101, 'systolic_bp': 145, 'patient_dob': '1980-05-20'},
{'id': 102, 'systolic_bp': 140, 'patient_dob': '1990-01-01'},
{'id': 103, 'systolic_bp': 130, 'patient_dob': '1975-12-12'}
]
# Assuming 140 is included:
# get_hypertension_records(records, 1, 2) -> {'data': [101, 102], 'total': 2, 'page': 1}
Hints
Hint 1
Clarify with the interviewer whether 'greater than' vs 'greater than or equal to' is the intended business rule before writing the loop.
Hint 2
Sort the entire filtered dataset by ID first to ensure that pagination is stable across multiple API calls.
Hint 3
Handle pagination indexing by calculating the slice start as `(page - 1) * page_size` and the slice end as `start + page_size`.
Follow-up questions
- How would you modify this code to handle 10 million records instead of a list in memory?
- If the 'patient_dob' field is required to calculate if a patient is over 65, what edge cases arise with leap years or time zones?
- How would you ensure that the API response is consistent if new records are being inserted into the database while a user is navigating through pages?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.