CS-OA cs-vo Faang

[TikTok] AMS Intern Assessment 2024 Start – 25 – 29 Mar (Generic)

1. Retail Inventory

A retail inventory management system developed in Java has Product and PerishableProduct classes representing items in the inventory.

A store manager decides to iterate over each Product object and call its calculateDiscount() method to apply the appropriate discount.

If the inventory includes both Product and PerishableProduct objects, which discount rate will be applied to PerishableProduct objects?

Pick ONE option

  • No discount will be applied.
  • 5% discount will be applied.
  • 10% discount will be applied.
  • The discount rate will be determined at runtime.

(The correct answer, indicated by a selection, is "10% discount will be applied.")

2. Blue-Green Deployment

A software organization develops a critical web application that serves millions of users globally. The organization adopts a Blue-Green deployment strategy on their Kubernetes cluster to ensure high availability and zero downtime during updates. During one of the updates, after the Green environment was live and the traffic was switched, some users reported that they were still running the old version of the application.

What is a solution to prevent this?

Pick ONE option

  • Increase the number of replicas in the Green deployment.
  • Force users to clear their browser cache.
  • Implement a stronger health check mechanism before routing traffic.
  • Utilize session affinity or sticky sessions in the service configuration.

(The correct answer, indicated by a selection, is "Implement a stronger health check mechanism before routing traffic.")

3. Authentication System

Develop a session-based authentication system where each user session generates a new token with a specified time-to-live (TTL) expiration. The TTL expiration is calculated as the current time plus the time-to-live seconds. If a token is renewed, the TTL is extended to the time-to-live seconds after the time of the renewal.

There are three types of queries in this system:

  • "generate <token_id> <current_time>": Creates a new token with the given token_id and current_time.
  • "renew <token_id> <current_time>": Renews an unexpired token with the given token_id and current_time. If there is no unexpired token with the specified token_id, the request is ignored.
  • "count <current_time>": Returns the number of unexpired tokens at the given current_time.

Note: If a token expires at a specific time and any action is performed at that same time, the token's expiration occurs before any other actions are carried out.

Example Suppose time_to_live = 5, and queries = ["generate aaa 1", "renew aaa 2", "count 6", "generate bbb 7", "renew aaa 8", "renew bbb 10", "count 15"].

The output of the system is [1, 0]. At t = 6, the only unexpired token is "aaa". At t = 15, all tokens have expired, so the count of unexpired tokens is 0.

Function Description Complete the function getUnexpiredTokens in the editor below.

getUnexpiredTokens has the following parameter(s):

  • int time_to_live: the time to live for a token
  • string queries[q]: the queries


  • int[]: the results from type-3 query in the same order it is given.

4. Server Investment

A network security administrator must protect networks at several locations from cyber-attacks.

Initially, the ith network has num_server[i] servers, and money[i] funds allocated for security upgrades. To upgrade a server in the ith network, it costs upgrade[i]. Selling a server adds sell[i] to available funds.

Formally, Given the arrays num_servers, money, upgrade, and sell, each with n integers, determine the maximum number of servers that can be upgraded to ensure optimal network security.

The result should be an array of n integers, where the ith integer represents the maximum number of upgraded servers for the ith network system.

Example num_servers = [4, 3] money = [8, 9] sell = [4, 2] upgrade = [4, 5]

SystemDescriptionNumber of upgraded servers
1stA server can be sold at a cost of 4 and upgraded at a cost of 4.There can be 3 upgraded servers
If one server is sold, the total amount left is 8 + 4 = 12 and 3
servers will be left. Now each server can be upgraded at a cost
of 4 each
2ndOne server can be sold for a cost of 2 amounting to a totalThe number can be 2 upgraded servers
money of 11 units which can be used to upgrade both of the
remaining servers at a cost of 10 units

5. TikTok Dance Moves

A TikTok participant is engaging in a challenge where they have a binary string representing a sequence of dance moves. The string consists of 0s and 1s, with 0s signifying pauses and 1s representing dance moves.

The participant can choose exactly k distinct positions in the string to modify. These modifications involve flipping the moves at those positions, converting 0s to 1s and 1s to 0s.

The objective is to maximize the count of pairs of consecutive dance moves (1s) in the final dance sequence. In TikTok challenges, participants aim to create the smoothest dance transitions.

Your task is to assist the participant in determining the maximum possible number of pairs of consecutive dance moves (1s) in the final dance sequence after the allowable adjustments.

Note that the count of pairs of consecutive 1s represents the number of indices (1 ≤ i < n) where s[i] = '1' and s[i+1] = '1', showcasing the seamless dance transitions in the challenge.

Example n = 5 s = "01010" k = 2

Following are some possible selection of positions in s:

Selected indicesResulting stringNumber of pairs of consecutive 1s

给不熟悉tiktok OA的朋友们科普一下,tiktok的OA每两周开放一次,当第一次OA未通过时可以再次申请两周后的OA,一般是周一开始做,周五截止。潜规则是周五做OA的人一般不会通过,而越早完成通过率越高。For those who are not familiar with TikTok's OA, it opens every two weeks. When the first OA is not passed, you can reapply for the OA after two weeks, which is generally started on Monday and ends on Friday. The unwritten rule is that people who do the OA on Friday generally do not pass, and the earlier you complete it, the higher the pass rate.



如果害怕自己解决不了OA,请扫码联系我 or telegram

If you're afraid that you can't solve the OA on your own, please scan the code to contact me or telegram

Leave a Reply

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