Validate Six-Column Business CSV Rows
Problem statement
rows[0] is a six-column header. Validate every later comma-separated row and return one label per data row. Fields do not contain commas, quoting, or escapes.
Apply these rules in order and report only the first failure:
RULE_1: exactly six trimmed fields, each nonempty.RULE_2: the trimmed fifth field has length from 5 through 31 inclusive.RULE_3: no whitespace token in the second field is a case-insensitive member offorbiddenWords.RULE_4: remove case-insensitiveignoreWordsfrom the distinct lowercase whitespace tokens of field two. At least half of the remaining words, rounded up, must appear in the distinct lowercase non-ignored tokens of field four or field five. If no word remains from field two, this rule fails.
Return VALID or INVALID:RULE_X.
Function
validateBusinessRows(rows: String[], forbiddenWords: String[], ignoreWords: String[]) → String[]Examples
Example 1
rows = ["id,name,type,description,code,status","1,Acme LLC,vendor,Acme services,12345,active","2,Bad Corp,vendor,Other,12345,active"]forbiddenWords = ["bad"]ignoreWords = ["llc","corp"]return = ["VALID","INVALID:RULE_3"]The first row has an overlapping word after ignoring LLC; the second fails the forbidden-word rule first.
Example 2
rows = ["h1,h2,h3,h4,h5,h6","1,Alpha Beta,x,beta market,alpha,ok","1,Alpha Beta,x,none,alpha,ok","1,,x,a,12345,ok"]forbiddenWords = []ignoreWords = []return = ["VALID","VALID","INVALID:RULE_1"]Rules are checked in order, and both valid rows meet the one-of-two overlap threshold.
Example 3
rows = ["a,b,c,d,e,f","1,LLC LLC,x,llc,llc12,ok"]forbiddenWords = []ignoreWords = ["llc"]return = ["INVALID:RULE_4"]A second field with no non-ignored word fails rule four.
Constraints
2 <= rows.length <= 100000.- The header has exactly six comma-separated fields.
- Each row and word-list entry has at most 1000 characters.
- The combined input length is at most
2 * 10^6.