[TikTok] OA 2025 Start – 20 Feb (Generic)
  1. Factorial Calculation

Implement a function factorial(n) that calculates the factorial of a given number n. Choose the correct implementation.

function factorial(n) {
    if (n <= 1) {
        return 1;
    }
    return n * factorial(n - 1);
}
  1. Prime Number Check

Write a function isPrime that returns true if a number n is prime and false otherwise. Select the correct implementation.

function isPrime(n) {
    if (n <= 1) {
        return false;
    }
    for (i = 2; i < n; i++) {
        if (n % i === 0) {
            return false;
        }
    }
    return true;
}
  1. Finding Maximum in Array

Implement a function findMax that returns the largest number in an array arr. Choose the correct option.

function findMax(arr) {
    var max = arr[0];
    for (i = 1; i < arr.length; i++) {
        if (arr[i] > max) {
            max = arr[i];
        }
    }
    return max;
}
  1. Balancing Server Loads with Dynamic Data Structure

A web server distributes load across multiple servers to balance traffic. To ensure real-time load balancing, the server with the least load should be dynamically selected as requests arrive. Which implementation method best achieves real-time selection of the least-loaded server?

Pick ONE option:

  1. Option 1:
    • Initialize array loads.
    • Sort loads in ascending order.
    • Return first element as least-loaded server.
  2. Option 2:
    • Initialize min-heap loads.
    • For each request:
      • server = extract_min loads
      • Process request on server
      • Re-insert server with updated load

  1. Real-Time Navigation System Using Dijkstra’s Algorithm

A company developing a real-time navigation system needs an efficient algorithm to find the shortest path from a user’s location to a destination across a large network of roads and intersections. The system must update dynamically as new road conditions and traffic data are received.

Which of the following pseudocode implementations best suits the requirement for finding the shortest path in a weighted graph?

Pick ONE option:

  1. Option 1:
    • Initialize empty queue path.
    • Enqueue start node to path.
    • While path is not empty:
      • node = dequeue path
      • If node is destination:
        • Return shortest path
      • Add all connected nodes to path.
  2. Option 2:
    • Initialize empty set visited.
    • Initialize stack path.
    • Push start node to path.
    • While path is not empty:
      • node = pop path
      • If node is destination:
        • Return path
      • For each neighbor of node:
        • If neighbor not in visited:
          • Push neighbor to path.
  3. Option 3:
    • Initialize priority queue pq.
    • Initialize distances to infinity for all nodes.
    • Set distance of start node to 0.
    • Add start node to pq.
    • While pq is not empty:
      • node = extract_min pq
      • For each neighbor of node:
        • If distance to neighbor > distance to node + edge weight:
          • Update distance to neighbor.
          • Add neighbor to pq.

我们长期稳定承接各大科技公司如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.

Leave a Reply

Your email address will not be published. Required fields are marked *