Count Invalid Log Groups
Updated
Problem statement
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>>) → intExamples
Example 1
logGroups = [["DOWN","UP","DOWN"],["UP","DOWN"],["DOWN","DOWN","UP"],["DOWN"]]return = 2The 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 = 2The 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 = 0There 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".
More IBM Online Assessment questions
- Missing IntervalsOA · Seen Nov 2026
- Last Object Exit TimeOA · Seen Nov 2026
- Count Peaks and ValleysOA · Seen Nov 2026
- Count Strictly Increasing Contiguous WindowsOA · Seen Nov 2026
- Total Each Letter's Count in an Encoded StringOA · Seen Nov 2026
- Count Servers With No Requests in a Time WindowOA · Seen Nov 2026
- Maximum Easy Tasks After RearrangingOA · Seen Nov 2026
- Tree Pythagorean TriplesOA · Seen Oct 2026
- Minimum Power-of-Two Removal OperationsOA · Seen Oct 2026
- Maximum Compatible Time WindowsOA · Seen Oct 2026
Similar questions at other companies
- REST API: Highest International StudentsRippling · OA
- Filter Transaction Logs and Calculate Reliability MetricsStripe · OA
- Compare Character Arrays with BackspacesOdoo · OA
- Slowest Key PressRoblox · OA
- Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
- Best TV Show in a GenreAdyen · OA
- Cheating CodemakerJane Street · OA
- Correct Apartment Bedroom CountsRamp · OA
- Reflow and Fully Justify Text LinesIntuit · OA
- Cumulative Typosquatting DetectionPalantir · OA