1. [OA] Job Scheduler — Design a Job Scheduler for ByteDance’s task management system
As part of ByteDance's operations, we need to design a job scheduling system that can queue and execute tasks efficiently. Implement a class that handles job scheduling with the ability to execute tasks at specified intervals. Problem Statement: Design a class JobScheduler with the following methods: - JobScheduler() — Initializes a job scheduler. - void scheduleJob(string jobId, int interval, function jobFn) — Schedules a job to run every interval milliseconds. - void cancelJob(string jobId) — Cancels the job with the given jobId. - Example 1: Input: JobScheduler(), scheduleJob("job1", 3000, jobFn), cancelJob("job1") Constraints: - 1 <= interval <= 10000
system designSeniorapi design#2
2. [OA] Rate Limiter — Design a Rate Limiter for ByteDance's API
ByteDance's APIs need a mechanism to limit the rate of requests to maintain service quality. Implement a rate limiter that controls the number of requests each user can make per minute. Problem Statement: Design a class RateLimiter with the following methods: - RateLimiter(int limitPerMinute): Constructor to set the limit on requests per user. - bool isAllowed(string userId): Determine if a request from userId is allowed for the current minute. - void recordRequest(string userId): Record that a request was made by userId. - Example 1: Input: RateLimiter(5), isAllowed("user1") => true, recordRequest("user1"), isAllowed("user1") => true, recordRequest("user1") => true (repeats until limit reached) Constraints: - 1 <= limitPerMinute <= 100
codingHardsliding window#3
3. [OA] Sliding Window — Longest Substring with K Distinct Characters in ByteDance’s social media feed
ByteDance's social media feed often presents users with posts that have various tags. Implement an algorithm that finds the longest substring containing at most k distinct characters. Problem Statement: Write a function longestSubstring(s: str, k: int) -> int that returns the length of the longest substring containing at most k distinct characters. - Example 1: Input: longestSubstring("eceba", 2) Output: 3 Explanation: The longest substring is "ece". - Example 2: Input: longestSubstring("aa", 1) Output: 2 Explanation: The longest substring is "aa". Constraints: - 1 <= s.length <= 10^5 - 0 <= k <= |s|
codingHarddynamic programming#4
4. [OA] Dynamic Programming — Maximum Product Subarray in ByteDance’s e-commerce catalog
In ByteDance's e-commerce app, we analyze product performances using their price impact over periods. Calculate the maximum product of a contiguous subarray of product prices. Problem Statement: Write a function maxProduct(nums: List[int]) -> int that returns the maximum product of a contiguous subarray in the given integer array nums. - Example 1: Input: maxProduct([2, 3, -2, 4]) Output: 6 Explanation: The maximum product is 2 * 3 = 6. - Example 2: Input: maxProduct([-2, 0, -1]) Output: 0 Explanation: The maximum product is 0. Constraints: - 1 <= nums.length <= 2 * 10^4 - -100 <= nums[i] <= 100