Reported July 2025
TikTokarray

Check Monotonic Triples

Reported by candidates from TikTok's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live TikTok OA. Under 2s to a working solution.
Founder's read

The first thing you notice in this TikTok OA, reported in July 2025, is the output length: arr.length - 2, one flag per window of three. That's the whole problem. It's a fixed-size window scan, not a stack problem despite the hint tag. If you've got an invite for the next day or two, this one is a warm-up you can't afford to overthink. The risk is sloppy comparisons, not hard algorithms. If you blank under the clock, StealthCoder sits invisibly on your screen and hands you the loop so you can finish clean.

The problem

You are given an integer array arr. Determine whether every sequence of three consecutive elements, arr[i], arr[i + 1], and arr[i + 2], is monotonic.
Three consecutive elements are monotonic when their values are in strictly increasing or strictly decreasing order.
Return an integer array of length arr.length - 2. For every valid index i, set the i-th result to 1 if either arr[i] < arr[i + 1] < arr[i + 2] or arr[i] > arr[i + 1] > arr[i + 2]. Otherwise, set it to 0.
A solution with time complexity no worse than O(arr.length^2) will fit within the execution time limit.

Function
solution(arr: int[]) → int[]

Examples
Example 1
arr = [1,2,1,-4,5,10]
return = [0,1,0,1]
[1, 2, 1] is not monotonic.
[2, 1, -4] is strictly decreasing.
[1, -4, 5] is not monotonic.
[-4, 5, 10] is strictly increasing.
Example 2
arr = [10,10,10,10,10]
return = [0,0,0]
All values are equal, so no sequence of three elements is strictly increasing or strictly decreasing.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that there isn't one. Walk i from 0 to n-3, compare arr[i], arr[i+1], arr[i+2], and write 1 if a < b < c or a > b > c, else 0. That's O(n) time and O(n) output. The pitfall is equality. Example 2 is all tens, and the answer is all zeros because the order must be strict. Using <= or >= will fail that case. The second pitfall is array length. If arr has fewer than 3 elements, the result should be empty, so make sure your loop bound doesn't produce a negative-size array. Don't reach for a stack, a sort, or nested loops. The statement even allows O(n^2), which tells you the checker is forgiving. StealthCoder is your hedge on the live OA if nerves make you second-guess something this simple, but you should have this written in about two minutes.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Check Monotonic Triples 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. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass TikTok's OA.

TikTok reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Check Monotonic Triples FAQ

How hard is the TikTok Check Monotonic Triples problem really?+

Easy. It's a single pass over the array with a three-element comparison per window. The only real difficulty is reading carefully. Strictly increasing or strictly decreasing means equal neighbors fail. Most candidates finish it in a few minutes if they avoid overengineering.

What's the trick to solving it?+

There's no trick beyond strictness. Loop i from 0 to length minus 3, check arr[i] < arr[i+1] < arr[i+2] or arr[i] > arr[i+1] > arr[i+2], and push 1 or 0. Use strict operators so equal values return 0, as in the all-tens example.

Do I need a stack even though it was tagged stack?+

No. The tag is misleading. Each window depends only on three adjacent values, so no state carries between windows. A plain for loop and a result array is the cleanest answer and runs in linear time.

What edge cases should I test?+

Test arrays with equal values like [10,10,10,10,10], arrays of exactly three elements, and arrays shorter than three. Also test a window where only two of the three are ordered, like [1,2,1]. That should return 0, not 1.

How do I prepare in 48 hours for an OA like this?+

Practice writing sliding-window and array-scan loops quickly and cleanly, paying attention to loop bounds and strict versus non-strict comparisons. Read the output spec twice before coding. Expect a TikTok OA to mix easy scans like this with something harder, so budget your time.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with TikTok.

OA at TikTok?
Invisible during screen share
Get it