Salesforce logo

Salesforce Hard Interview Questions

1 hard-level practice questions for Salesforce technical interviews

No verified questions yet for Salesforce.

coding Hard sliding window #1

1. [OA] Sliding Window — Optimize Salesforce's API request handling

To improve the performance of API requests and reduce response times, Salesforce needs to implement an algorithm to handle bursts of requests within a specific time frame.
Given a list of int timestamps representing the arrival times of API requests and an integer windowSize, your task is to determine the maximum number of API requests that can be handled within any windowSize seconds.
Method Signature:
def maxRequestsWithinWindow(timestamps: List[int], windowSize: int) -> int:
Example 1:
Input: timestamps = [1, 2, 3, 5, 6]
Output: 4
Explanation: The requests at times 1, 2, 3, and 5 can all be handled within a 5-second window (from time 1 to 6).
Example 2:
Input: timestamps = [1, 3, 6, 8, 10]
Output: 3
Explanation: The requests at times 6, 8, and 10 can all be handled within a 5-second window (from time 6 to 11).
Constraints:
- 1 <= len(timestamps) <= 10^5
- 0 <= windowSize <= 10^6
- 0 <= timestamps[i] <= 10^6

Start practicing Salesforce questions

Sign up for free to access walkthroughs, AI-generated questions, and more.

Get Started Free