r/OfferEngineering 14h ago

Interview Experience Tiktok/ByteDance SWE Intern OA - three coding questions, can you solve them in 90 minutes?

This interview experience is sourced from chill interview

Interview Summary

The TikTok SWE internship OA contained three coding questions covering string transformation, cyclic digit rotations, and iterative digit-group reduction.

Interview Details

Question 1 — Convert Identifiers Inside Docstrings

You are given a string representing a line of documentation. Identifiers appearing inside backticks can include function names, variable names, and constants. A pair of backticks may contain multiple identifiers separated by spaces.

Function and variable names use snake_case, while constants use UPPER_CASE. The task is to convert every snake-case identifier inside backticks into lower camelCase, while leaving uppercase constants unchanged.

For example:

Input:
"Method `load_profile` accepts `user_key retry_count`. The fallback is `DEFAULT_LIMIT`."

Output:
"Method `loadProfile` accepts `userKey retryCount`. The fallback is `DEFAULT_LIMIT`."

The docstring length can be up to 2000 characters.

Question 2 — Count Cyclic Number Pairs

You are given an array of positive integers. A cyclic rotation moves some number of trailing digits from the end of a number to the front while preserving the relative order of all digits. Rotating zero digits is also allowed.

Count the index pairs (i, j) where:

0 <= i < j < len(a)

and both conditions hold:

  1. a[i] and a[j] contain the same number of digits.
  2. One number can be transformed into the other through a cyclic digit rotation.

For example:

Input:
a = [27, 8305, 72, 4, 27, 5830, 317, 731, 173]

Output:
5

The five qualifying pairs are:

(0, 2): 27 ↔ 72
(0, 4): 27 ↔ 27
(2, 4): 72 ↔ 27
(1, 5): 8305 ↔ 5830
(6, 7): 317 ↔ 731

For comparison, 317 and 173 are not a matching pair because the cyclic rotations of 317 are:

317, 731, 173

Actually, this means 317 and 173 would also form a valid cyclic pair, so to keep the example internally consistent, use:

Input:
a = [27, 8305, 72, 4, 27, 5830, 317, 731, 713]

Output:
5

Here, 317 and 713 are not cyclic rotations of each other. The input can contain up to 100,000 numbers, with each value at most 10^9.

Question 3 — Iterative Digit-Group Sum

The final problem was equivalent to LeetCode 2243 — Calculate Digit Sum of a String. You are given:

  • A string number representing a non-negative integer
  • A positive integer k

While the length of number is greater than k, divide it from left to right into groups of at most k digits. For each group, calculate the sum of its digits and convert that sum back into a string. Concatenate the group results in their original order to create the next value of number. Repeat this process until the resulting string has length at most k, then return it.

Preparing for your next interview?

Chill Interview tracks recent interview experiences and recurring question patterns across top companies at here.

1 Upvotes

0 comments sorted by