I did not finish the OA.
First question: Maximum Game Score (LeetCode)
Problem description:
Given an integer array game_val of length n and an integer k, a player can start at any index in the array. From index i, the player can jump forward exactly k positions to index i + k, provided that index is within the array.
The player's score is the sum of all visited elements, including the starting position. Find the maximum possible score the player can obtain by choosing the best starting index.
Example:
Input: game_val = [2, -3, 4, 6, 1], k = 2.
Output: 7.
Explanation: Start at index 0. The path is 0 → 2 → 4. The score is 2 + 4 + 1 = 7.
Second question: Reliable LLM API Calls (Low-Level Design)
Task:
Implement reliable_call to interact with an LLM API and handle failures. This question leans toward system design, OOP, and exception handling.
Provided dependencies:
client.complete(messages): sends messages and may raise ClientError.
validate_fn(response): validates the response and may return False or raise ValidationError.
Requirements:
Preserve the original conversation history. Do not modify the original list reference; a deep copy is preferable.
Retry API failures when ClientError occurs.
Retry validation failures: append the failed response as an assistant message, followed by a corrective user message, then retry.
Keep independent counters: API-error retries and validation-error retries must be independent.
On successful validation, return the response directly.
When retries are exhausted, raise LLMRetryError with metadata: last_response, attempts, all_responses, and failure_reason.
Handle a retry budget of zero: no retries are allowed, so make just one call.
Specific hints:
When ClientError occurs, append CLIENT_ERROR_MESSAGE to messages.
When validate_fn raises ValidationError, use this corrective message:
f"That response was invalid: {reason}. Please try again with valid JSON."
An example of raising the exception when client-error retries are exhausted:
raise LLMRetryError(
"Client error limit reached",
last_response,
attempts,
all_responses,
"client_error"
)
attempts records the total number of API calls; all_responses records all responses that failed validation.
Discussion
Loading comments…