FastPrepFastPrep
Problem Brief

TikRouter Delivers

OA

Imagine you're in charge of TikTok's servers, where millions of videos, comments, and likes are constantly flowing between users.

TikTok needs to send these small packets of data across its network to keep users' feeds smooth and up-to-date. However, there's a catch! The TikTok delivery drone, which we'll call TikRouter, can only carry a limited amount of data on each trip between servers.

- Each "like," comment, or part of a video clip is between 1.01 bytes and 3.00 bytes in size. - TikRouter is responsible for delivering these packets of interactions to TikTok's users but can carry only up to 3.00 bytes per trip.

As the network administrator in charge of TikRouter, your goal is to minimize the number of trips it makes. Each time TikRouter makes a trip, it grabs as many likes, comments, and video snippets as it can without exceeding the 3.00-byte limit. After each delivery, TikRouter returns for more until all packets are delivered.

Your challenge is to design an efficient algorithm that helps TikRouter determine the minimum number of trips required to deliver n packets of varying sizes.

Function Description

Complete the function findMinimumTripsByTikRouter in the editor below.

findMinimumTripsByTikRouter has the following parameter(s):

  1. float packet_sizes[n]: size of the data packets (in bytes)

Returns

int: the minimum number of trips required

1Example 1

Input
packet_sizes = [1.01, 1.99, 2.5]
Output
2
Explanation

TikRouter can deliver all the data packets in two trips: [1.01 + 1.99, 2.5].

Thus, the answer is 2.

Constraints

Limits and guarantees your solution can rely on.

๐Ÿ‰๐Ÿ‰
public int findMinimumTripsByTikRouter(float[] packet_sizes) {
  // write your code here
}
Input

packet_sizes

[1.01, 1.99, 2.5]

Output

2

Sign in to submit your solution.