[Tiktok] OA Assessment 2025 Start – 4 Jan

6. TikTok Twin Pairs

The TikTok development team is working on a feature to help creators come up with better captions for their videos. TikTok's algorithm favors engaging captions, so you are building an AI tool that paraphrases captions to make them catchier.

However, TikTok charges creators based on the number of characters that get changed after paraphrasing. Therefore, you are tasked with reducing TikTok creators' costs by identifying "twin-strings" from the captions to avoid paraphrasing the same content multiple times.

Two strings are considered as "twin-strings" if they are composed of the same characters, regardless of their arrangement or frequency.

For example, "viral" and "rival" are "twin-strings" since both are composed of the same five characters: 'v', 'i', 'r', 'a', and 'l'. However, "viral" and "trend" are not "twin-strings" since they do not share all the same letters.

Given an array of n strings, determine the number of pairs (i, j) such that 0 ≤ i < j < n and (words[i], words[j]) are "twin-strings."

Note: Each string is composed of lowercase English characters only.


Example

n = 5
words = ["apple", "aple", "silent", "listen", "papel"]

Note the following case:

  • Strings "apple," "aple" and "papel" are made up of the same unique characters: 'a', 'p', 'e' and 'l'. Thus, any pair of them forms a "twin-strings" pair.
  • Strings "silent" and "listen" are also "twin-strings" because they are made up of the same unique characters: 's', 'i', 'l', 'e', 'n' and 't'.
Index (i)WordTwin-strings with index > iTwin-strings pairs
0appleaple, papel(0, 1), (0, 4)
1aplepapel(1, 4)
2silentlisten(2, 3)
3listen--
4papel--

Thus, there are 4 such pairs that satisfy the condition 0 ≤ i < j < n and (words[i], words[j]) are "twin-strings." Therefore, the answer is 4.


Function Description

Complete the function countTwinPairs in the editor below.

countTwinPairs has the following parameter(s):

  • string words[n]: an array of n strings

Returns

  • long: the number of valid pairs of "twin-strings" in the given array.

Constraints

  • 1 ≤ n ≤ 10⁵
  • The sum of the lengths of all strings does not exceed 10⁶.
  • All strings consist of lowercase English characters only.

Input Format for Custom Testing

  • The first line contains an integer, n, the number of strings in words.
  • Each of the next n lines contains a string, words[i].

Sample Case 0

Sample Input for Custom Testing

STDIN               FUNCTION
-----               --------
4                   words[] size n = 4
abca                words = ["abca", "abaa", "baab", "cba"]
abaa
baab
cba

Sample Output

2

7. TikTok Spam Filter

TikTok Content Moderation Team is working to help creators manage their video comments effectively, ensuring a positive environment by identifying spammy behavior in the comments section.

You have a total of n videos and k keywords that you want to monitor for spammy behavior in the comments. The comments are collected in an array called comments, while the keywords that indicate spammy behavior are stored in another array called spam_keywords.

A comment is flagged as spam if it contains at least two instances of the keywords in the spam_keywords array.

Your task is to analyze the comments for each video and return an array of n strings, labeling each comment as either "spam" or "not_spam" based on the presence of the keywords.

Note: If a keyword appears multiple times in a comment, each occurrence counts toward the spam threshold. Also note that keyword matching should be case-insensitive.


Example

n = 3
comments = ["Viral tricks to boost", "Great viral tips", "boost views and go viral"]
k = 2
spam_keywords = ["viral", "boost"]

commentsspam_keywordsTotal count in spam_keywords arrayType
Viral tricks to boostviral, boost1 + 1 = 2spam
Great viral tipsviral1not_spam
boost views and go viralviral, boost1 + 1 = 2spam

Hence the answer is ["spam", "not_spam", "spam"].


Function Description

Complete the function getSpamComments in the editor below.

getSpamComments takes the following arguments:

  • string comments[n]: an array of strings representing comments on TikTok videos
  • string spam_keywords[k]: an array of strings containing keywords that signify spammy behavior

Returns

  • string[n]: the results of spam detection

Constraints

  • 1 ≤ n ≤ 10³
  • 1 ≤ k ≤ 10⁵
  • 1 ≤ |comments[i]| ≤ 10⁵
  • 1 ≤ |spam_keywords[i]| ≤ 10⁵
  • It is guaranteed that the sentences and search words consist of lowercase and uppercase English letters and spaces only.

Input Format for Custom Testing

  • The first line contains an integer, n, the number of elements in comments.
  • Each of the next n lines contains a string, comments[i].
  • The next line contains an integer, k, the number of elements in spam_keywords.
  • Each of the next k lines contains a string, spam_keywords[i].

Sample Case 0

Sample Input for Custom Testing

STDIN                FUNCTION
-----                --------
2                    comments[] size n = 2
The sun is bright    comments = ["The sun is bright", "Blockbuster bonanza"]
Blockbuster bonanza  
3                    spam_keywords[] size k = 3
bright               spam_keywords = ["bright", "bonanza", "paid"]
bonanza
paid

Sample Output

not_spam
not_spam

Explanation
The first comment contains only one spam_keyword "bright". The second comment also contains only a single spam_keyword "bonanza". Since both these comments contain only 1 spam_keyword therefore both are flagged as "not_spam".


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