MEDIUMasked at 1 company

Longest Unequal Adjacent Groups Subsequence II

A medium-tier problem at 51% community acceptance, tagged with Array, String, Dynamic Programming. Reported in interviews at fourkites and 0 others.

Founder's read

Longest Unequal Adjacent Groups Subsequence II is a medium DP problem that shows up in real OAs despite low visibility. The trick is recognizing that you can't just greedily pick elements; you have to track state across groups and reject consecutive duplicates intelligently. FourKites has asked it. The acceptance rate hovers around 51%, which means half the people who attempt it blank or submit a wrong answer. This is the kind of problem where the obvious greedy approach fails, and you hit a wall in the live assessment. If this one lands in your OA and you haven't drilled the DP construction, StealthCoder solves it in seconds, invisible to the proctor.

Companies asking
1
Difficulty
MEDIUM
Acceptance
51%

Companies that ask "Longest Unequal Adjacent Groups Subsequence II"

If this hits your live OA

Longest Unequal Adjacent Groups Subsequence II is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made for the engineer who has done the work but might still blank with a webcam pointed at him.

Get StealthCoder
What this means

The problem asks you to find the longest subsequence where adjacent elements come from different groups. The gotcha is that 'different groups' doesn't mean just checking the previous element; it means tracking which group the last selected element came from, then only accepting elements from a different group. Most candidates try a greedy approach or a simple one-dimensional DP that collapses under the constraint. The real solution requires building state: for each position and each group, track the longest valid subsequence ending at that group. You'll iterate through the array, and for each group, you ask: what's the longest valid subsequence I can extend from all other groups. This is O(n*m) where m is the number of groups. The tricky part is managing the group transitions correctly without double-counting or missing overlaps. When you're in the live OA and realize your first pass doesn't handle the group logic right, StealthCoder provides the correct DP skeleton so you don't tank the submission.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Longest Unequal Adjacent Groups Subsequence II recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made for the engineer who has done the work but might still blank with a webcam pointed at him. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Longest Unequal Adjacent Groups Subsequence II interview FAQ

Is this still being asked at real companies?+

Yes. FourKites has confirmed it. The low acceptance rate and medium difficulty suggest it's not a household name, but it's active in the interview loop. If your target companies include logistics or supply-chain tech, this is worth knowing.

What's the main trick I'm missing if I fail this?+

You're probably trying greedy or a 1D DP that doesn't track group state. The actual solution requires a 2D DP (or equivalent state machine) where you separately store the best subsequence ending at each group, then transition by picking from a different group.

How does this relate to the other DP topics I'm drilling?+

It combines Array and String DP patterns. It's harder than basic longest-subsequence problems because the constraint isn't just 'pick numbers in order'; it's 'pick numbers in order from alternating groups'. That state-transition twist is what separates it from standard LIS variants.

If I've only drilled classic DP, will I spot the pattern?+

Probably not quickly. Classic longest-subsequence DP tracks one value at a time. Here you track one value per group and compare across groups. If you haven't seen that pattern, you'll waste 15-20 minutes on the assessment, which is why having a backup matters.

What's the real time complexity I should aim for?+

O(n*m) where n is array length and m is the number of distinct groups. With reasonable constraints, this is fast enough. Anything exponential or O(n^2) per group is a red flag that your DP isn't structured right.

Want the actual problem statement? View "Longest Unequal Adjacent Groups Subsequence II" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.