今天给大家带来的是选择题部分,另外第七题有一个变种,
之前的分享见 之前的文章
1. Implementing Load Balancing in a Microservices Architecture
TikTok is adopting a microservices architecture for its applications. Efficient load balancing is critical to ensure that services remain responsive under varying loads. Which load balancing strategy would best distribute requests across microservices?
Pick ONE option:
- Round Robin
- Least Connections
- IP Hash
- Random
2. Optimizing Warehouse Inventory with Balanced Binary Search Trees
A large logistics company stores its inventory data in a system. The data includes item IDs and quantities in stock. As the company expands, it becomes increasingly difficult to efficiently manage inventory searches, updates, and deletions. The CTO decides to redesign the inventory management system to ensure that search, insert, and delete operations remain efficient even as the number of items grows significantly. Which data structure is the best choice for this scenario?
Pick ONE option:
- Unbalanced Binary Search Tree (BST)
- Balanced AVL Tree
- Circular Queue
- Doubly Linked List
3. TikTok Expression Evaluation
TikTok uses stacks to evaluate mathematical expressions. Given an expression in postfix notation, write a pseudo-code to evaluate it using a stack.
Pick ONE option:
for each token in expression {
if (token is operand) {
stack.push(token);
} else {
op2 = stack.pop();
op1 = stack.pop();
result = evaluate(op1, token, op2);
stack.push(result);
}
}
return stack.pop();
for each token in expression {
if (token is operand) {
stack.push(token);
} else {
op1 = stack.pop();
op2 = stack.pop();
result = evaluate(op1, token, op2);
stack.push(result);
}
}
return stack.pop();
plaintext复制代码for each token in expression {
if (token is operand) {
stack.push(token);
} else {
op2 = stack.pop();
op1 = stack.pop();
result = evaluate(op2, token, op1);
stack.push(result);
}
}
return stack.pop();
for each token in expression {
if (token is operand) {
stack.push(token);
} else {
op1 = stack.pop();
op2 = stack.pop();
result = evaluate(op2, token, op1);
stack.push(result);
}
}
return stack.pop();
4. TikTok News Feed
TikTok uses a queue to manage articles to be displayed in the user's news feed. Write a pseudo-code to implement the enqueue operation for adding a new article to the queue.
Pick ONE option:
if (queue is full) {
return "Queue is full";
} else {
queue.add(newArticle);
return queue;
}
if (queue is empty) {
queue.add(newArticle);
} else {
return "Queue is full";
}
return queue;
if (queue is not full) {
queue.add(newArticle);
}
return queue;
if (queue is full) {
return "Queue is full";
} else {
queue.add(newArticle);
return queue;
}
5. Circular Queue Task Removal Implementation
TikTok uses a circular queue to manage tasks. Choose the correct pseudo-code to implement the dequeue operation for removing a task from the queue.
Pick ONE option:
if (queue is empty) {
return "Queue is empty";
} else {
task = queue.remove();
return task;
}
if (queue is full) {
return "Queue is empty";
} else {
task = queue.remove();
return task;
}
if (queue is empty) {
task = queue.remove();
return task;
} else {
return "Queue is empty";
}
if (queue is empty) {
return "Queue is empty";
} else {
task = queue.remove();
return task;
}
7.JavaScript/TypeScript: JSON Transformer
In modern applications, data often needs to be restructured to fit various requirements, such as API specifications or database schemas. Transforming JSON objects to match these criteria, including flattening nested structures and renaming keys, is a common task in software development.
Write a function that transforms a nested JSON object into a flattened JSON object. The keys of the flattened JSON should be constructed by concatenating the keys from the nested structure, separated by an underscore (_), and the values should be the corresponding values from the nested JSON. If an array is encountered, each element of the array should be indexed and included as part of the key.
Example:
For example, given the input JSON object:
{
"id": 12345,
"name": "SampleObject",
"details": {
"created_at": "2024-08-15T12:34:56Z",
"status": "active",
"metadata": {
"type": "example",
"priority": "high",
"tags": ["tag1", "tag2", "tag3"]
}
}
}
The function should output:
{
"id": 12345,
"name": "SampleObject",
"details_created_at": "2024-08-15T12:34:56Z",
"details_status": "active",
"details_metadata_type": "example",
"details_metadata_priority": "high",
"details_metadata_tags_0": "tag1",
"details_metadata_tags_1": "tag2",
"details_metadata_tags_2": "tag3"
}
我们长期稳定承接各大科技公司如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.