DEV Community

Cover image for TikTok OA High-Frequency Coding Questions (2026) – Full Breakdown + Python Solutions
net programhelp
net programhelp

Posted on

TikTok OA High-Frequency Coding Questions (2026) – Full Breakdown + Python Solutions

In this guide, we’ve compiled 4 classic TikTok OA problems along with detailed explanations and ready-to-submit Python solutions. If you're preparing for TikTok or similar tech company assessments, these patterns show up very frequently.

1. Uppercase vs Lowercase Difference

Given a string typedText containing both uppercase and lowercase letters, return the difference: uppercase count minus lowercase count.

Examples:

  • "CodeSignal" → -6
  • "a" → -1
  • "AbCdEf" → 0

The idea is straightforward: iterate through the string and count uppercase and lowercase letters separately.

def solution(typedText):
    upper = 0
    lower = 0
    for c in typedText:
        if c.isupper():
            upper += 1
        elif c.islower():
            lower += 1
    return upper - lower

2. Drone Delivery Walking Distance

You start at position 0 and need to reach a target. There are charging stations along the way. You always walk to the nearest station ahead, then let the drone deliver as far as possible. Repeat until reaching the target. Return total walking distance.

Examples:

  • target = 23, stations = [7,4,14] → 4
  • target = 27, stations = [15,7,3,10] → 7

This is a simulation problem. At each step, find the nearest station ahead and accumulate walking distance.

def solution(target, stations):
    current = 0
    walk = 0
    while current < target:
        ahead = [s for s in stations if s > current]
        if not ahead:
            walk += target - current
            break
        nearest = min(ahead)
        walk += nearest - current
        current = nearest
    return walk

3. Newspaper Text Alignment

Format paragraphs with a fixed width and alignment (LEFT or RIGHT), and wrap everything with a border of '*'.

Key steps: split words into lines within width limit, apply alignment padding, then add borders.

def solution(paragraphs, aligns, width):
    result = []
    result.append('*' * (width + 2))
    
    for i in range(len(paragraphs)):
        words = paragraphs[i]
        align = aligns[i]
        line = []
        current_len = 0
        
        for word in words:
            if not line:
                line.append(word)
                current_len = len(word)
            else:
                new_len = current_len + 1 + len(word)
                if new_len <= width:
                    line.append(word)
                    current_len = new_len
                else:
                    line_str = ' '.join(line)
                    spaces = width - len(line_str)
                    if align == "LEFT":
                        line_str += ' ' * spaces
                    else:
                        line_str = ' ' * spaces + line_str
                    result.append(f'*{line_str}*')
                    
                    line = [word]
                    current_len = len(word)
        
        if line:
            line_str = ' '.join(line)
            spaces = width - len(line_str)
            if align == "LEFT":
                line_str += ' ' * spaces
            else:
                line_str = ' ' * spaces + line_str
            result.append(f'*{line_str}*')
    
    result.append('*' * (width + 2))
    return result

4. Longest Consecutive House Segment

You build houses one by one on a number line. After each build, return the length of the longest consecutive segment.

Example:

  • [2,1,3] → [1,2,3]

Use hash maps to track segment boundaries and merge intervals efficiently.

def solution(queries):
    left = {}
    right = {}
    max_len = 0
    res = []
    
    for pos in queries:
        cur_len = 1
        l = pos
        r = pos
        
        if pos - 1 in right:
            cur_len += right[pos - 1] - left[pos - 1] + 1
            l = left[pos - 1]
        
        if pos + 1 in left:
            cur_len += right[pos + 1] - left[pos + 1] + 1
            r = right[pos + 1]
        
        left[l] = l
        right[l] = r
        left[r] = l
        right[r] = r
        
        max_len = max(max_len, cur_len)
        res.append(max_len)
    
    return res

Extra High-Frequency Questions

Minimum Height Difference with Gap Constraint

def solution(heights, viewingGap):
    min_diff = float('inf')
    n = len(heights)
    for a in range(n):
        for b in range(a + viewingGap, n):
            diff = abs(heights[a] - heights[b])
            if diff < min_diff:
                min_diff = diff
    return min_diff

Battery Usage Simulation

def solution(t, capacity, recharge):
    n = len(capacity)
    recharge_time = [0] * n
    time_used = 0
    full_batteries = 0
    i = 0
    
    while time_used < t:
        if recharge_time[i] <= time_used:
            use_time = min(capacity[i], t - time_used)
            time_used += use_time
            if use_time == capacity[i]:
                full_batteries += 1
            recharge_time[i] = time_used + recharge[i]
        else:
            i = (i + 1) % n
            if all(rt > time_used for rt in recharge_time):
                return -1
    
    return full_batteries

Interview Tips

These problems focus heavily on simulation, iteration, and edge case handling. TikTok OA usually doesn't require extremely complex algorithms, but it does require strong implementation accuracy under time pressure.

Before submitting:

  • Test edge cases (empty input, single element, max constraints)
  • Watch for off-by-one errors
  • Keep code clean and readable

Need Help with OA or Interviews?

If you're dealing with tight deadlines, multiple OAs, or high-stakes interviews, having real-time guidance can make a huge difference.

We provide:

  • Live coding assistance
  • Real-time hints during assessments
  • Mock interviews with detailed feedback

Check pricing and get help here

Top comments (0)