TikTok Online Assessment Questions - 2023 SWE Internship USA (Please help with answers)

Question 1: A company is working on a new algorithm that operates on a special CPU that can handle n types of tasks, and the priority of the ith task is represented by the array priority[i]. The CPU will run for y seconds and you can choose to perform which follows the given conditions:

  • In each second, you can choose to perform any available task from the n types (if there are any tasks to perform)
  • It is allowed to perform multiple tasks of the same type within the given time frame, but there is a time constraint that there must be atleast x seconds between any two consecutive tasks of the same type.
  • It is not allowed to perform more than one task at any second.

Given n tasks, an array priority, and an integer x and y, find the maximum possible sum of the priority tasks performed during the y seconds.

Question 2:
company is planning to buy some GPUs for training their new computer vision models using them. They have two clusters on which all the models are saved. There are 'n' GPUs available where the cost of the 'i'th GPU is represented by array element cost[i]. Also, there are 2 arrays 'compatible1' and 'compatible2', each containing 'n' integers, where each integer is either 0 or 1, representing the following: 1. If compatible1[i] = 1, then the i th GPU is compatible with cluster 1, else it is not compatible with cluster 1. 2. If compatible2[i] = 1, then the i th GPU is compatible with cluster 2, else it is not compatible with cluster 2. the company wants to buy the GPUs such that there are atleast a min_compatible number of GPUs compatible with each of cluster 1 and cluster 2. Given 'n' GPUs, an integer min_compatible and arrays cost, compatible1, and compatible2, find the minimum possible cost of GPUs such that there are atleast a min_compatible number of GPUs compatible with each of cluster 1 and cluster 2. Return "-1" if it is not possible to buy the GPUs satisfying the above condition.

Comments (3)