TikTok OA, All 4 Passed: Min in a Range, Sorting by Vowel Gap, Bouncing Diagonals, Subarrays with at Least k Fruit Pairs
TikTok OA recap with all four passed: the minimum inside an open range, sorting words by the vowel/consonant gap, sorting by bouncing-diagonal weight, and counting subarrays with at least k pairs of the same fruit using a sliding window, with Python reference code.
Q1: Minimum inside an open range
Keep the elements with nRange[0] < x < nRange[1] and return the smallest; return 0 if none qualify.
def min_in_open_range(nums, n_range):
lo, hi = n_range
return min((x for x in nums if lo < x < hi), default=0)
Q2: Sort words by vowel gap
For each word, count its vowels v and compute |v − (word length − v)|. Sort by this gap ascending, breaking ties alphabetically.
def sort_by_vowel_gap(words):
def gap(w):
v = sum(ch in "aeiouAEIOU" for ch in w)
return abs(v - (len(w) - v))
return sorted(words, key=lambda w: (gap(w), w))
Q3: Sort by bouncing-diagonal weight
For each element in the first column, walk the bouncing diagonal from (r, 0) — the row at column c is abs(r − c) — and sum the values to get its weight. Then sort by (weight, value).
For the full approach and code, see TikTok 2027 Intern OA (10/2), question 3.
Q4: Count subarrays with at least k pairs of fruit
Use a sliding window that tracks each fruit's frequency along with the number of pairs, sum(freq // 2):
- Keep extending the right edge.
- While the window has at least k pairs, shrink from the left.
- Count every valid subarray ending at the current right edge.
from collections import defaultdict
def count_subarrays_with_k_pairs(fruits, k):
freq, pairs, left, total = defaultdict(int), 0, 0, 0
for x in fruits:
freq[x] += 1
if freq[x] % 2 == 0:
pairs += 1 # a new pair is formed
while pairs >= k: # [left..right] is valid; move left forward
y = fruits[left]
if freq[y] % 2 == 0:
pairs -= 1
freq[y] -= 1
left += 1
total += left # every start in 0..left-1 is valid
return total
Time O(n). The key insight: growing the window can only add pairs, so validity is monotonic in the left edge — which is what makes two pointers work.
Found this helpful? Let's talk.
Happy to swap interview notes, do mock interviews, or share referral info.

Scan to add me on WeChat
More TikTok notes
View all ›- TikTok Data Engineer Interview | TikTok New Grad, Full ProcessTikTok · 2026-10-04›
- TikTok 2027 CodeSignal OA: Even Digit Count, Cyclic-Shift Difference Sums, Bouncing Diagonals, Most Points in a RangeTikTok · 2026-10-03›
- TikTok Data Science OA, 4 Questions Done in 28 Minutes: Metrics, Table Merges, Feature Preprocessing, Random Forest Threshold TuningTikTok · 2026-10-03›
- Four Classic TikTok OA Questions: Adjacent Character Changes, Closest Earlier Timestamp, Placing Shapes, Fewest Operations to an Arithmetic SequenceTikTok · 2026-10-03›