TikTok (ByteDance) 2026 new-grad OA on HackerRank, four questions, cleared all of them in one pass.
Q1: Given a string, ignoring case, count how many positions have s[i] != s[i+1]. Just walk through it once.
Q2: Simulate addition — for each digit, add the digit's contribution directly into the answer. Straightforward simulation, that's all it takes.
Q3: Given a 0/1 array, you need to support two operations: alloc x and erase id. For alloc, scan left to right for the first run of x consecutive 0s whose starting index is a multiple of 8, then set that whole run to 1 and assign it all to that id. For erase, zero out everything equal to that id — if the id doesn't exist, or has already been erased, return -1. I kept two arrays: the original 0/1 array, and a second array t that records where each id's block is. For alloc, brute-force the candidate starts 0, 8, 16, ..., k*8, then check whether the next x cells are all 0 — if so, set that whole segment to the current id. For erase, just scan through in order and clear anything matching. That's the whole thing.
Q4: Every time you add a point, report how many contiguous segments there are, where a segment is a run of same-colored points. I kept a map tracking the colors on either side of each point — when you add or change a point, check whether its color now differs from or matches its neighbors, and update the segment count from there. Just simulate it.
Discussion
Loading comments…