TikTok General Coding Assessment
✅ Question 1: Count Substrings With Vowels
You are developing an automatic moderation system for a chat application that detects certain linguistic patterns.
Given a string chatMessage
containing a sequence of characters, your task is to count the number of substrings of exactly length 3 where at least one character is a vowel ("a", "e", "i", "o", "u", or their uppercase counterparts). Return this number as an integer.
Note: You are not expected to provide the most optimal solution, but a solution with time complexity not worse than O(
chatMessage.length
²) will fit within the execution time limit.
Example:
- For
chatMessage = "CodeSignal"
, the output should besolution(chatMessage) = 8
. Explanation:
Substrings of length 3:"Cod"
,"ode"
,"deS"
,"eSi"
,"Sig"
,"ign"
,"gna"
,"nal"
All contain at least one vowel → 8 substrings - For
chatMessage = "StrEngThen"
, the output should besolution(chatMessage) = 5
. Explanation:
Substrings of length 3:"Str"
,"trE"
,"rEn"
,"Eng"
,"ngT"
,"gTh"
,"The"
,"hen"
Substrings with at least one vowel:"trE"
,"rEn"
,"Eng"
,"The"
,"hen"
→ 5 substrings
Input/Output
- [input] string
chatMessage
A sequence of characters representing a chat message.
Constraints:1 ≤ chatMessage.length ≤ 1000
- [output] integer
Number of substrings of length 3 with at least one vowel (case-insensitive).
✅ Question 2: Consonant Cipher Shift
You're implementing a simple substitution cipher that only affects consonant characters in a memo
.
This cipher works by shifting every k-th consonant to the following consonant in the alphabet, while leaving vowels and other characters unchanged.
Notes:
- Only consonant characters are affected:
'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z'
- When shifting from
'z'
, it wraps around to'b'
. - The case of each character must be preserved (uppercase stays uppercase, lowercase stays lowercase).
Note: A solution with time complexity not worse than O(
memo.length
²) will fit within the execution time limit.
Example:
Input:
memo = "CodeSignal"
k = 3
Output:
solution(memo, k) = "CodeTignam"
Explanation:
- Consonants:
'C', 'd', 'S', 'g', 'n', 'l'
- 3rd consonant
'S'
→'T'
- 6th consonant
'l'
→'m'
✅ Question 3: Molecular Bond Pairing
You are a chemist working in a laboratory that studies molecular compounds. You have two arrays representing the atomic weights of elements in two different compounds:
x
represents the primary elementsy
represents the secondary elements
Two compounds with the same balance factor (difference between primary and secondary atomic weights) can form stable bonds.
Your task:
Count the number of unique molecular pairings (i, j)
where i < j
and x[i] - y[i] == x[j] - y[j]
.
Example:
- Input:
x = [2, -2, 5, 3]
y = [1, 5, -1, 1]
- Output:
solution(x, y) = 6
Explanation:
- Compute all
x[i] - y[i]
:
→1, -7, 6, 2
- Count pairs
(i, j)
with same result.
Input/Output
- [input] 2 arrays of integers
x
andy
Each of lengthN
- [output] integer
Number of valid(i, j)
pairs such thatx[i] - y[i] == x[j] - y[j]
andi < j
✅ Question 4: Teleport Labyrinth
Imagine that you're exploring a mysterious labyrinth in the shape of a rectangular matrix, which contains obstacles and teleports.
Your goal is to reach the lower-right corner by only moving to the right starting from the upper-left corner.
Input:
- Integers
n
andm
: dimensions of the labyrinth. - Lists of pairs:
obstacles
: cells that cannot be passedteleports
: list of[start_row, start_col, end_row, end_col]
for one-way teleportation
Movement Rules:
- You always move to the right (from
[row, col]
to[row, col + 1]
) - If you reach a cell that is a teleport start, you are moved instantly to its end cell
- Obstacles block movement completely
- You stop if you move outside bounds or hit an obstacle
- Cells with no obstacles or teleports are free to walk through
Output:
- Return the number of cells traversed, including start and teleport endpoints
- Return
-1
if blocked by obstacle or out of bounds - Return
-2
if stuck in infinite teleport loop - Return
-3
if unable to reach goal but not due to obstacle or teleport loop
Example:
n = 3
m = 3
obstacles = [[2, 1]]
teleports = [[0, 1, 2, 0]]
Grid:
[0,0] [0,1]*T [0,2]
[1,0] [1,1] [1,2]
[2,0] [2,1]X [2,2]
- You start at
[0,0]
, move to[0,1]
→ teleport to[2,0]
- Cannot move right to
[2,1]
because it's an obstacle
→ Return-1

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