DEV Community

Cover image for TikTok OA Questions: 4 Coding Problems Solved in Under 30 Minutes
interviewshow-cs
interviewshow-cs

Posted on

TikTok OA Questions: 4 Coding Problems Solved in Under 30 Minutes

Just finished another TikTok Online Assessment on CodeSignal. This one took less than 30 minutes to complete all four questions.

The difficulty wasn't particularly high. Most of the problems were focused on implementation, simulation, and basic algorithm patterns. The main challenge was reading the requirements carefully and not missing small constraints.

Here are the four questions I encountered this time.

T1: Product of Digits Minus Sum of Digits

Given a positive integer n, calculate the product of all digits minus the sum of all digits.

For example:

n = 123456

Product = 1 × 2 × 3 × 4 × 5 × 6 = 720
Sum = 1 + 2 + 3 + 4 + 5 + 6 = 21

Answer = 720 - 21 = 699

The implementation is straightforward. Repeatedly use n % 10 to extract the last digit and n //= 10 to remove it.

Maintain two variables for the product and sum, then return product - sum.

Time complexity: O(log n)

One small detail: use a sufficiently large integer type because the intermediate product can become much larger than the original number.

T2: Add One Pair of Parentheses to an Addition Expression

This one looks simple but has several conditions that are easy to misread.

Given an expression consisting of two positive integers separated by +, such as:

741+12

You must add exactly one pair of parentheses.

  • The + must be inside the parentheses.
  • There must be at least one digit on both sides of the + inside the parentheses.
  • The goal is to minimize the resulting expression value.

For each valid placement of the parentheses, calculate the value in the form:

leftNumber × (insideLeft + insideRight) × rightNumber

Since the string is short, there is no need for anything complicated. I simply enumerate all valid positions for the left and right parentheses, calculate the resulting value, and keep the minimum.

The important part is making sure the enumeration respects all the constraints around the + sign.

T3: Memory Allocation and Release

This was a classic simulation problem.

The memory array uses:

  • 0 for a free memory unit
  • 1 for an occupied memory unit

There are two operations.

alloc X

Scan from left to right and find the first contiguous block containing at least X free units.

Mark that block as occupied and return its corresponding ID or starting index, depending on the exact problem specification.

erase ID

Use the ID to locate the previously allocated block and turn those memory units back to 0.

My implementation used:

Array simulation + HashMap

The HashMap stores the mapping between the allocation ID and its corresponding memory range. This makes the erase operation straightforward.

One thing to watch out for is fragmentation. After multiple alloc and erase operations, the free memory may be split into many small blocks. Each new allocation still needs to search from the left for the first valid contiguous block.

T4: Place a Lamp to Cover the Maximum Number of Objects

Given an array objects containing object coordinates in ascending order, place a lamp at an integer coordinate.

The lamp has a coverage radius of radius, so a lamp placed at coordinate c covers:

[c - radius, c + radius]

The goal is to maximize the number of covered objects. If multiple positions cover the same maximum number of objects, return the smallest valid lamp coordinate.

The clean solution is a Sliding Window.

Maintain a window from l to r. As long as:

objects[r] - objects[l] ≤ 2 × radius

there exists a lamp position that can cover the entire window.

Move the right pointer forward, and when the window becomes too wide, move the left pointer forward.

For every valid window, track:

  • the maximum number of objects covered
  • the smallest lamp coordinate when the coverage count is tied

Time complexity: O(n)

Quick Summary

Question Core Concept
T1 Digit Simulation
T2 Enumeration + String Processing
T3 Array Simulation + HashMap
T4 Sliding Window

Overall, this was a very implementation-heavy OA. There wasn't much advanced algorithmic theory involved.

The biggest things to pay attention to were the small requirements:

  • Product minus sum, not the other way around
  • Exactly one pair of parentheses
  • The + must be inside the parentheses
  • First contiguous free block for allocation
  • For equal maximum coverage, choose the smaller lamp coordinate

If you can quickly recognize basic patterns such as simulation, enumeration, HashMap, and Sliding Window, this type of OA becomes much more manageable.

TikTok CodeSignal assessments also share some common patterns with OA processes at companies such as Amazon, Microsoft, Uber, Roblox, and others. Practicing implementation-heavy problems under time pressure can make a noticeable difference.

How to Prepare for TikTok OA

For this type of assessment, I would prioritize speed and accuracy over grinding extremely difficult problems.

  • Practice common CodeSignal-style implementation problems.
  • Review Sliding Window, HashMap, sorting, and array simulation.
  • Practice reading long problem statements quickly.
  • Pay special attention to tie-breaking rules and edge cases.
  • Do timed practice so that four questions in one session doesn't feel unfamiliar.

If you're preparing for TikTok or other software engineering OA/VO processes, InterviewShow also provides interview preparation resources, including Coding, System Design, behavioral interview preparation, and mock interview practice.

Final Takeaway

This TikTok OA was a good reminder that not every assessment is about solving the hardest possible algorithm problem.

Sometimes the difference between passing and failing is simply whether you noticed one sentence in the requirements.

For implementation-heavy OA questions, I would rather be extremely comfortable with the fundamentals and finish four medium-level problems cleanly than spend all my preparation time on difficult algorithms.

Top comments (0)