FastPrepCount Invalid Log Groups
Problems/Count Invalid Log Groups

Count Invalid Log Groups

IBM logoIBM● EasyNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an IBM new grad online assessment. The report gives the rules for when a group is valid. It does not give the nested-list format, the fixed set of UP and DOWN words, what to do with empty input, or the input limits. For this version, empty groups are invalid, a group with a single DOWN is valid, a group with a single UP is invalid, and an empty list of groups returns zero. Our version is about 94% the same as the reported question.

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".

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

IBM interview experiences

  • IBM Full-Time SWE OA Questions: 1 Experience
  • IBM Software Intern Résumé Rounds: 2 Experiences (Part 3 of 3)
  • IBM Intern Blitz Interviews: 23 Experiences (Part 2 of 3)
  • IBM Software Intern Interviews: 44 Experiences (Part 1 of 3)
  • IBM Software Intern Interview Questions: 15 Experiences
See IBM hiring insights
Saved
class Solution {
    public int countInvalidLogGroups(List<List<String>> logGroups) {
      // Write your code here.
    }
}
Checking account…