Question 1: Priority Processes
Problem Statement
Given n processes that need to be executed. Among these n processes, k are classified as high-priority processes, with their indices (1-based) represented in the array high_priority[i].
An OS scheduler is responsible for overseeing the execution of all processes. When a scheduler assigns a set of processes to a processor, it has two options:
- If the assigned processes are greater than 1 and even, it can divide the array of processes, denoted as
p
, into two contiguous subarrays of equal size,p1
andp2
. The scheduler will then allocatep1
to one processor andp2
to another. - Alternatively, the scheduler can choose to execute the assigned array of processes,
p
. The time required for process execution is determined based on the following criteria:- If the assigned processes do not include any high-priority processes, the scheduler will take normal_time seconds to complete all the assigned processes.
- If there are high-priority processes among the assigned tasks (denoted as x), it will take priority_time * x * l seconds to complete them, where l is the total number of assigned processes.
The total time required to execute all processes is the sum of the time taken by all processors for their assigned tasks. The task is to minimize the total execution time by optimizing the assignment of processes to processors within the operating system.
Question 2: LFU Cache
Problem Statement
Implement a Least Frequently Used (LFU) cache data structure of size cacheSize that handles two types of queries: GET and PUT.
- A GET query attempts to retrieve the value of a given key:
- If the key is present in the cache, it is returned.
- Otherwise, it returns
-1
.
- A PUT query updates or inserts a key-value pair into the cache:
- When the cache is full, the least frequently used key is evicted to insert the new key-value pair.
- If there is a tie in the frequency of keys, then the least recently used key is removed.
Return an array of integers where each element represents the answer for the corresponding GET query.
Example
Suppose cacheSize = 1, q = 5, queries = ["PUT 1 1", "PUT 2 2", "GET 1", "PUT 2 2", "GET 1"]
Only one element is stored in the cache at a time.
Output:
[-1]
Constraints
- 2 ≤ cacheSize ≤ 10
- 1 ≤ q ≤ 10^5
- Queries contain at least 1 query of type GET.
- |queries[i]| ≤ 13
- Key and value consist of digits ('0' - '9') only.
- Value of key ≤ 300
- Value of value ≤ 10^6
我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。
We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.