Save 25%Black Friday: 25% off all plans — use code BLACKFRIDAY2026 at checkout. Ends Monday, Dec 7.Claim the deal

You are developing a data ingestion component for a large-scale analytics platform. The platform receives raw data in a simplified CSV format, where each line represents a record with specific attributes. Before storage or analysis, all incoming data must be strictly validated to maintain data quality and comply with business requirements.

The system provides three inputs:

  1. data: A list of strings, with each string representing a row in a CSV table containing n rows and 6 columns per row. Each row follows the format "col1,col2,col3,col4,col5,col6", and the first row is always the header.
  2. forbiddenWords: A list of strings containing words that are prohibited in specific fields.
  3. ignoreWords: A list of strings consisting of common words (stop words) that should be ignored only during cross-column content comparison.

For each data row (excluding the header), determine whether it is "VALID" or "INVALID" by applying the following four rules in order:

  • RULE_1: Schema & Completeness.
    Every column value must be non-empty after trimming any leading or trailing whitespace.

  • RULE_2: Column 5 Length Check.
    The 5th column (col5), once trimmed, must have a length between 5 and 31 characters (inclusive).

  • RULE_3: Forbidden Words in Column 2.
    The 2nd column (col2) must not contain any word from forbiddenWords.

    • Matching is case-insensitive.
    • Words are defined as tokens separated by whitespace.
  • RULE_4: Cross-Column Word Match.
    A valid word is a lowercase word not found in ignoreWords. The row meets this rule only if at least 50% of valid words in col2 are also present as valid words in either col4 or col5.

    • If col2 has zero valid words, the row is invalid.
    • Repeated valid words in col2 are only counted once for percentage calculation.

If a row satisfies all rules, label it as "VALID". If it fails any rule, label it as "INVALID: RULE_X", where X is the number of the first failed rule. Return a list of validation results of length n - 1 (excluding the header), with each result corresponding to a data row.

Constraints:

  • 11 ≤ data.length ≤ 10410^4
  • data[i] consists of ASCII characters.
  • forbiddenWords and ignoreWords can contain up to 10310^3 elements.
  • Fields are separated strictly by a single comma (',').
  • There is no support for quotes or escape characters.
  • Commas will never appear as part of the content within a field.

Example 1:

Input: data = ["col1,col2,col3,col4,col5,col6",                "id1,Land Water,c,d,land water llc,f",                "id2,Good Company,c,d,land water,f",                "id3,Apple banana,c,d,banana orange,f",                "id4, ,c,d,hello world,f",                "id5,LLC Inc,c,d,something real,f",                "id6,blue sky ocean,c,d,green yellow pink,f",                "id7,Best Group,c,d,hello group,f",                "id8,land water,c,d,land,f"], forbiddenWords = ["company", "firm", "co.", "corporation", "group"], ignoreWords = ["llc", "inc"] Output: ["VALID", "INVALID:RULE_3", "VALID", "INVALID:RULE_1", "INVALID:RULE_4", "INVALID:RULE_4", "INVALID:RULE_3", "INVALID:RULE_2"] Explanation: All violations are listed below:

  • Row 2: col2 violates "RULE_3" as it contains forbiddenWords "Company". It violates "RULE_3".
  • Row 4: col2 violates "RULE_1" as it contains only whitespace.
  • Row 5: col2 violates "RULE_4" as both words are in ignoreWords.
  • Row 6: col2 violates "RULE_4" as words ("blue", "sky", "ocean") do not appear in col4 or col5.
  • Row 8: col5 violates "RULE_2"as its length is 4.

Example 2:

Input: data = ["col1,col2,col3,col4,col5,col6",                "id1,hello world,c,d,hello there,f"], forbiddenWords = ["bad", "wrong"], ignoreWords = [] Output: ["VALID"]

Example 3:

Input: data = ["col1,col2,col3,col4,col5,col6",                "id1,good name,c,d,test,f"], forbiddenWords = [], ignoreWords = [] Output: ["INVALID:RULE_2"]


Accepted
3.5k/11.1k
Acceptance Rate31.3%
Test Cases
Input
data =
forbiddenWords =
ignoreWords =
Output
Expected