TikTok OA (8/13), Same Questions Again: 4 CodeSignal Problems in 70 Minutes, All Passed
TikTok OA on CodeSignal: 4 coding questions in 70 minutes, all passed in half an hour. Exactly two equal among three consecutive numbers, remaining segments after destroying houses (reverse restore), a+b pair counting with updates (frequency maps), and sorting matrix borders layer by layer.
Overview
- Platform: CodeSignal
- Format: 4 coding questions in 70 minutes
- Result: done in half an hour, all passed ✅
Q1: Exactly two equal among three consecutive numbers
Scan the array, look at every three consecutive numbers, and check whether exactly two are equal. Just list the three cases with an if: a == b != c, a == c != b, b == c != a. O(n).
def count_exactly_two_equal(nums):
count = 0
for a, b, c in zip(nums, nums[1:], nums[2:]):
if (a == b != c) or (a == c != b) or (b == c != a):
count += 1
return count
Q2: Remaining segments after destroying houses
Approach: work backwards. Start from the state after every house in the queries has been destroyed, then "restore" houses one by one, starting from the last one destroyed:
- Both neighbors exist: two segments merge into one — count decreases by 1.
- Only one neighbor exists: it extends an existing segment — count unchanged.
- Neither neighbor exists: it forms a new segment — count increases by 1.
Record the count before each restore, then reverse the list for the answer.
def segments_after_each_destroy(houses, queries):
"""houses: house positions; queries: houses destroyed in order. Returns the segment count after each destruction"""
alive = set(houses) - set(queries)
count = sum(1 for h in alive if h - 1 not in alive) # number of segment starts = number of segments
res = []
for q in reversed(queries):
res.append(count)
left, right = q - 1 in alive, q + 1 in alive
if left and right:
count -= 1
elif not left and not right:
count += 1
alive.add(q)
return res[::-1]
Q3: a + b pair counting with updates
Maintain frequency maps for both arrays:
- Query type 1 (given x): for each value in a, count how many
x - a[i]exist in b and add them up. - Query type 0 (update
a[i]): update the value and a's frequency map (decrement the old value, increment the new one).
Optimal isn't required; an O(n) scan per query is fine.
from collections import Counter
def process_queries(a, b, queries):
a = list(a)
ca, cb = Counter(a), Counter(b)
res = []
for q in queries:
if q[0] == 0: # [0, i, x]: set a[i] to x
_, i, x = q
ca[a[i]] -= 1
a[i] = x
ca[x] += 1
else: # [1, x]: count pairs with a[i] + b[j] == x
x = q[1]
res.append(sum(cnt * cb[x - v] for v, cnt in ca.items() if cnt))
return res
Q4: Sort matrix borders
Process the matrix layer by layer from the outside in. For layer k (starting at 0), take the ring's elements in clockwise order — top edge left to right, right edge top to bottom, bottom edge right to left, left edge bottom to top — sort them, and write them back in the same order.
Go up to layer floor((n-1)/2). Each layer is O(n) to read and write, so O(n² log n) overall is plenty.
def sort_borders(matrix):
n = len(matrix)
m = [row[:] for row in matrix]
for k in range((n + 1) // 2):
lo, hi = k, n - 1 - k
if lo == hi:
continue # the center of an odd-sized matrix is a single cell
coords = ([(lo, c) for c in range(lo, hi)] + # top edge: left -> right
[(r, hi) for r in range(lo, hi)] + # right edge: top -> bottom
[(hi, c) for c in range(hi, lo, -1)] + # bottom edge: right -> left
[(r, lo) for r in range(hi, lo, -1)]) # left edge: bottom -> top
vals = sorted(m[r][c] for r, c in coords)
for (r, c), v in zip(coords, vals):
m[r][c] = v
return m
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›
- TikTok OA, All 4 Passed: Min in a Range, Sorting by Vowel Gap, Bouncing Diagonals, Subarrays with at Least k Fruit PairsTikTok · 2026-10-03›