Count Invalid Log Groups
Reported by candidates from IBM's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Empty groups count as invalid, and a lone "UP" does too. That's the detail that trips people on this IBM OA, reported in August 2026. The task is Count Invalid Log Groups. You get a list of status lists, each holding "UP" or "DOWN", and you return how many break the rules. A valid group starts with "DOWN" and alternates all the way through. It's a plain array scan with no fancy structure. If you blank on the edge cases under the clock, StealthCoder can run invisibly during the live assessment as a safety net. Most candidates won't need it here.
The problem
You are given logGroups, a list of log groups. Each group is an ordered list of status strings, and every status is either "UP" or "DOWN". A group is valid only when both rules hold: Its first status is "DOWN". Every pair of adjacent statuses is different, so the statuses alternate between "DOWN" and "UP". An empty group is invalid because it has no first "DOWN" status. A one-status group is valid exactly when that status is "DOWN". If logGroups is empty, return 0. Return the number of invalid groups. Implement countInvalidLogGroups(List<List<String>> logGroups). Function countInvalidLogGroups(logGroups: List<List<String>>) → int Examples Example 1 logGroups = [["DOWN","UP","DOWN"],["UP","DOWN"],["DOWN","DOWN","UP"],["DOWN"]] return = 2 The second group is invalid because it starts with "UP". The third group is invalid because its first two adjacent statuses are both "DOWN". The first and fourth groups are valid, so the result is 2. Example 2 logGroups = [[],["DOWN","UP"],["UP"]] return = 2 The empty group is invalid, the alternating two-status group is valid, and the singleton "UP" group is invalid. Therefore the answer is 2. Example 3 logGroups = [] return = 0 There are no groups to classify, so there are no invalid groups. Constraints 0 <= logGroups.length <= 10^5. 0 <= logGroups[i].length. The total number of statuses across all groups is at most 2 * 10^5. Every status is exactly "UP" or "DOWN".
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is that there isn't one. Loop over each group and check validity in a single pass. If the group is empty, mark it invalid. If the first status isn't "DOWN", mark it invalid. Then walk indices 1 through the end and flag the group the moment two adjacent statuses match. Count the invalid ones and return the total. Total work is linear in the number of statuses, which fits the 2 * 10^5 cap easily. The common pitfalls are all edge cases: reading the first element of an empty list and crashing, treating a singleton "UP" as valid, and forgetting that an empty outer list returns 0. Compare strings with equals, not ==, if you're in Java. Break out early on the first violation to keep it tidy. If your head goes blank mid-OA, StealthCoder is the hedge, but this one is mostly careful reading.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Count Invalid Log Groups 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. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass IBM's OA.
IBM reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Count Invalid Log Groups FAQ
How hard is the IBM Count Invalid Log Groups question really?+
Easy. It's a single-pass validation over nested lists. The difficulty is only in the edge cases: empty groups, one-element groups, and an empty outer list. If you handle those three explicitly, the rest is a simple loop with an adjacent comparison.
What's the trick to solving it fast?+
Write a helper that returns true if a group is invalid. Check empty first, then check the first element is "DOWN", then compare each element to the one before it. Count how many times the helper returns true. Checking empty before indexing avoids the most common crash.
What's the time complexity I should state?+
O(N) where N is the total number of statuses across all groups, since each status is looked at once. Extra space is O(1) because you only keep a counter. With N up to 2 * 10^5, that's comfortably fast and no optimization is needed.
Which edge cases should I test before submitting?+
Test an empty outer list (returns 0), a group that is empty (invalid), a single "DOWN" (valid), a single "UP" (invalid), and a group that alternates correctly but starts with "UP". Also test a group where the violation is only at the very end.
How do I prepare for this in 48 hours?+
Practice writing array validation loops with early exits, and get comfortable with nested list iteration in your language. Rehearse the empty and singleton cases out loud. This question type rewards careful reading over clever algorithms, so reread the validity rules once before you code.