tiktok 字节 bytedance 8/24-8/28 OA
想要了解更多或获取我们的服务,欢迎添加微信 leetcode-king
Problem Statement
The TikTok team is working on enhancing an AI model that curates personalized content feeds. A performance metric called initialEngagementScore
is defined to measure how well the AI is currently performing. The team aims to improve this score to a targetEngagementScore
.
There are n
data sets available for training, represented by trainingEngagementScore
, where trainingEngagementScore[i]
denotes the potential improvement from the i-th data set. The AI model can only be trained on a data set if its current engagement score is greater than or equal to the score of the data set. Training the AI on the i-th data set increases its score by trainingEngagementScore[i]
. Moreover, the AI model can be trained on each data set only once.
On each day, the team can do either of the following:
- Train the AI model on any data set.
- Manually increase the engagement score of the AI by the number of days since training started.
Your task is to find the minimum number of days required for the AI model to reach the targetEngagementScore
.
题目分析与解决方案
在这道题目中,TikTok团队需要最小化天数以提升AI模型的表现,从而达到targetEngagementScore
。每一天,团队可以选择在一个数据集上训练AI模型,或者手动增加AI的参与度分数。我们的目标是找到一种策略,能以最少的天数达到目标分数。
代码示例
下面是一个有效的Python解决方案,它使用贪心算法和优先队列来优化训练过程:
import heapq
def minDaysToTargetEngagement(initialEngagementScore, targetEngagementScore, trainingEngagementScore):
trainingEngagementScore.sort()
cand = []
days = 0
i = 0
while initialEngagementScore < targetEngagementScore:
days += 1
while i < len(trainingEngagementScore) and trainingEngagementScore[i] <= initialEngagementScore:
heapq.heappush(cand, -trainingEngagementScore[i])
i += 1
if len(cand) == 0 or -cand[0] < days:
initialEngagementScore += days
else:
initialEngagementScore -= cand[0]
heapq.heappop(cand)
return days
Problem Statement
The TikTok team is analyzing clips to measure their unique content strength. Given a string clip
of length n
consisting of only lowercase English characters, imagine the clip is circular, meaning after the n-th character, the sequence continues from the 1st character again.
Circular Nature
Since the clip is circular, you can form substrings that wrap around from the end of the string back to the beginning. For instance, with the string "xyz"
, valid substrings include "y"
, "x"
, "z"
, "yx"
, "xz"
, "zy"
, "yxz"
, "xyz"
, and "zxy"
.
The "content strength" of a circular clip is determined by the number of unique substrings that consist of only consonants. Your task is to find the content strength of this circular clip.
Example
Input:
clip = "bac"
Output:
3
Explanation:
The different possible substrings of the circular clip are: ["b", "a", "c", "ba", "ac", "cb", "bac", "acb", "cba"]
.
The substrings that consist of only consonants are: ["b", "c", "cb"]
.
Thus, the content strength is 3
.
题目分析与解决方案
在这道题目中,TikTok 团队希望计算环形字符串中独特内容强度。要解决这个问题,我们需要找到所有仅包含辅音的独特子串。由于字符串是环形的,这使得子串可以从字符串末尾环绕回开头。
代码示例
以下是一个Python解决方案,该方案使用集合和循环来计算符合条件的子串数量:
def calculateContentStrength(clip):
n = len(clip)
new_clip = clip + clip
v = set()
vowels = "aeiou"
for i in range(2*n):
if new_clip[i] in vowels:
continue
for j in range(i, 2*n):
if j-i+1 > n or new_clip[j] in vowels:
break
v.add(new_clip[i:j+1])
return len(v)
为什么选择我们的服务?
如果您正在备战TikTok或其他科技公司的在线面试(OA)和技术面试,我们的OA代做和面试辅导服务正是您所需要的。我们的团队成员包括ACM奖牌得主和大厂资深TLM,具备丰富的技术面试经验。无论是代码代写、简历润色、还是面试辅导,我们都能提供一站式解决方案,帮助您快速拿到心仪的offer。
想要了解更多或获取我们的服务,欢迎添加微信 leetcode-king。我们会为您提供最优质的服务,让您在求职路上脱颖而出!