1p3a Question · Mar 2026

TikTok CodeSignal OA March High-Frequency Questions Summary

Question Details

You can find the interview experience and timeline here: <a href="https://reurl.cc/8e2rZR1

Problem: Given a memory array consisting of 0s and

Full Details

You can find the interview experience and timeline here: <a href="https://reurl.cc/8e2rZR1

Problem: Given a memory array consisting of 0s and 1s (0 = free, 1 = occupied). Memory is aligned by 8. Support an operation alloc x: find the leftmost contiguous block of x free units whose starting index is divisible by 8, allocate it (mark as occupied and assign a unique ID).

Return the starting index, or -1 if not found.

Approach: Simulate a memory management system. * Maintain an array of the same length to record the ID assigned to each position (0 means free). * For alloc x: iterate over valid starting indices (multiples of 8), check if the next x positions are all free. If yes, assign the current ID and increment the counter. * For erase ID: scan the entire array, reset all positions with that ID to 0, and return the number of cleared units. --- ### Q2

Problem: Given an integer array, count the number of contiguous subarrays that form a sawtooth sequence (adjacent elements have alternating parity).

Approach: Count all subarrays where adjacent elements alternate between even and odd. * A single element is also considered a valid sawtooth sequence. * Traverse the array and maintain the current length cur of alternating sequence. * If current and previous elements have different parity → cur++; otherwise reset cur = 1. * Add cur to the result at each step, since it represents the number of valid subarrays ending at the current index. --- ### Q3

Problem: Starting from position 0, repeatedly walk to the nearest charging station ahead, then use a drone to carry the cargo as far forward as possible. Continue until reaching the target. Compute the total distance you actually carry the cargo on foot.

Approach: Greedy simulation. * You can use stations p[i], where from p[i] the drone can move the cargo to p[i] + 10. * The goal is to count only the walking distance (excluding drone-traveled parts). * Sort the stations first. * Each round: find the next usable station ahead of your current position, add the walking distance to reach it, then update current position to station + 10. * Repeat until reaching or passing the target. --- ### Q4

Problem: Given multiple paragraphs, their alignment (LEFT or RIGHT), and a maximum line width, format the text like a newspaper: pack words greedily into lines, pad spaces according to alignment, and add a border of * around the entire output.

Approach: Simulate text formatting. * For each paragraph, use two pointers to pack as many words as possible into each line without exceeding width. * Build lines incrementally. * When outputting: * If LEFT → pad trailing spaces * If RIGHT → pad leading spaces * Finally, add a border of * around all lines. ---

Free preview. Unlock all questions →

Topics

Arrays Greedy Two Pointers