← 返回博客列表
TikTok

TikTok / ByteDance OA All 4 AC: Interval Lookup + Vowel Flip + Battery Scheduler + Chain Traversal

2026-03-18

TikTok / ByteDance OA All 4 AC

TikTok / ByteDance OA All 4 Questions AC Debrief

Just finished a ByteDance OA this morning — same CodeSignal platform as TikTok. 70 minutes, 4 questions, solved in ~15 minutes. All questions are drawn from a question bank. Here's the full breakdown.


Exam Overview

Item Details
Platform CodeSignal
Duration 70 minutes
Questions 4
Difficulty Easy ~ Medium
Role Intern / New Grad SDE
Result All AC, ~15 minutes

T1: Interval Lookup

Problem Summary

Given an initial value and an array, compute initial + sum(array), determine which interval it falls into, and return the corresponding label string.

Solution

def interval_lookup(initial: int, arr: list, intervals: list, labels: list) -> str:
    total = initial + sum(arr)
    for i, (lo, hi) in enumerate(intervals):
        if lo <= total < hi:
            return labels[i]
    return labels[-1]

# Example
print(interval_lookup(5, [3,2,1], [(0,5),(5,10),(10,20)], ["low","mid","high"]))
# total=11 → "high"

Time: O(n + k) | Space: O(1)

Key points:


T2: Vowel Word Flip

Problem Summary

For each word where both first and last characters are vowels, reverse the middle characters, keeping first and last unchanged.

Solution

def vowel_word_flip(words: list) -> list:
    vowels = set('aeiouAEIOU')
    result = []
    for word in words:
        if len(word) >= 2 and word[0] in vowels and word[-1] in vowels:
            result.append(word[0] + word[1:-1][::-1] + word[-1])
        else:
            result.append(word)
    return result

# Example
print(vowel_word_flip(["abcde", "hello"]))
# abcde → a + "bcd"[::-1] + e = "adcbe"

Time: O(n·m) | Space: O(n·m)

Key points:


T3: Battery Scheduler

Problem Summary

Use phone for t minutes with n batteries of varying capacity and charge rate. Rotate batteries — when one dies, switch to a charged one. Find the minimum number of fully-charged batteries needed.

Solution

import heapq

def min_batteries(t: int, capacity: list, charge_rate: list) -> int:
    n = len(capacity)
    ready = [(0, i) for i in range(n)]
    heapq.heapify(ready)
    charging = []
    current_time = 0
    batteries_used = 0

    while current_time < t:
        while charging and charging[0][0] <= current_time:
            heapq.heappush(ready, heapq.heappop(charging))
        if not ready:
            return -1
        _, idx = heapq.heappop(ready)
        batteries_used += 1
        use_until = current_time + capacity[idx]
        if use_until >= t:
            return batteries_used
        charge_time = use_until + capacity[idx] / charge_rate[idx]
        heapq.heappush(charging, (charge_time, idx))
        current_time = use_until

    return batteries_used

Time: O(k log n) | Space: O(n)

Key points:


T4: Chain Traversal

Problem Summary

Given a chain (linear graph), output the traversal order starting from either endpoint.

Solution

from collections import defaultdict

def chain_traversal(n: int, edges: list) -> list:
    adj = defaultdict(list)
    for u, v in edges:
        adj[u].append(v)
        adj[v].append(u)

    start = next((node for node in range(1, n+1) if len(adj[node]) == 1), 1)
    path, prev, curr = [start], None, start

    while True:
        nxt = next((nb for nb in adj[curr] if nb != prev), None)
        if nxt is None:
            break
        path.append(nxt)
        prev, curr = curr, nxt

    return path

print(chain_traversal(5, [(1,2),(2,3),(3,4),(4,5)]))
# [1, 2, 3, 4, 5]

Time: O(n) | Space: O(n)

Key points:


Complexity Summary

Question Algorithm Time Space
T1 Interval Lookup if-else O(n+k) O(1)
T2 Vowel Flip set + slice O(n·m) O(n·m)
T3 Battery Scheduler Greedy + heap O(k log n) O(n)
T4 Chain Traversal Adj list + while O(n) O(n)

Common Mistakes

Q Pitfall Fix
T1 Open/closed boundary confusion Read carefully, use < vs <=
T2 Single-char word edge case Guard len >= 2
T3 Mixed time units for charge Unify to minutes: use_until + cap/rate
T4 Full visited set causes issues On a chain, just track prev

CodeSignal OA Strategy

TikTok / ByteDance OA Profile

Exam Day Tips

  1. Scan all 4 questions first — start with the easiest
  2. T1/T2 should take under 5 min each — secure full marks first
  3. T3/T4 need simulation — watch edge cases, budget 20 min
  4. Run provided examples before submitting
  5. Review edge cases if time allows: empty arrays, single node, t=0

Related LeetCode Problems

# Problem Relevant To
1893 Check if Range is Covered T1
557 Reverse Words in a String III T2
1642 Furthest Building You Can Reach T3
1971 Find if Path Exists in Graph T4

🚀 Need TikTok / ByteDance OA Assistance?

oavoservice specializes in full-service OA/VO support for North American big tech. TikTok / ByteDance OA is one of our highest-frequency services with excellent question bank coverage.

Add WeChat: Coding0201

📱 WeChat: Coding0201 | 💬 Telegram: @OAVOProxy | 📧 [email protected]