Rearrange Students
Reported by candidates from TikTok's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
TikTok's November OA asked candidates to rearrange students, a problem that looks deceptively simple on first read but punishes incomplete thinking. You're given a list of students with some property or constraint, and you need to reorder them to satisfy a condition. The trick is figuring out what "rearrange" really means in context. Is it sorting by a key. Is it matching pairs. Is it satisfying a graph constraint. The wording matters. If you blank on pattern, StealthCoder reads the problem aloud and suggests the core structure in real time, giving you 90 seconds to remember instead of panic.
Pattern and pitfall
Without the full problem text, the most common TikTok student rearrangement problem involves either sorting students by a key (height, ID, performance) or matching students to seats or partners under constraints. If it's a sorting problem, you're likely doing a custom comparator or using a stable sort. If it's a matching or assignment problem, you might need graph matching, greedy assignment, or a simulation. The pattern is often greedy or simulation. The gotcha is almost always the edge case: what if two students have equal keys. What if no valid arrangement exists. What if the constraint is bidirectional (student A must sit next to student B). Study the examples closely. They encode the constraint language. StealthCoder will surface that constraint when you need it most during the live OA.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Rearrange Students cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as sort the matrix diagonally. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass TikTok's OA.
TikTok reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Rearrange Students FAQ
Is this a sorting problem or a graph/matching problem?+
Most likely sorting with a custom comparator, but read the problem twice. If it says 'match', 'pair', or 'arrange adjacent', it's matching. If it says 'order', 'sort', or 'arrange by', it's sorting. The verb matters.
What's the most common trap in TikTok student problems?+
Assuming the input is already valid. Almost always there's a case where no valid arrangement exists, or the output must handle ties. Test against the examples for ties and impossibility. Never assume happy path.
How much time should I spend understanding the constraint?+
30-40 seconds minimum. Re-read the problem statement once more than you think necessary. Most candidates lose 15 minutes because they misread 'adjacent' as 'any order'. Get the constraint bulletproof first.
Is a brute-force simulation fast enough?+
Depends on input size. If n is under 1000, a clean O(n log n) sort or O(n^2) simulation will pass. If n is 10k or larger, you need the optimized path. The problem will hint size in constraints.
Should I pre-sort the input before rearranging?+
Often yes. Sort by the primary key first, then apply the rearrangement logic. This reduces the search space and makes the pattern visible. Don't over-complicate with unsorted input.