Stateful Log Transform and Search
Learn this problemProblem statement
Process an ordered operation sequence for a logger that stores transformed logs in insertion order.
["REMOVE", log, target]: delete every non-overlapping literal occurrence of the non-emptytargetfrom left to right, store the result, and output its zero-based insertion index.["TRUNCATE", log, n]: keep the firstncharacters, store the result, and output its zero-based insertion index.["CAPITALIZE", log]: convert every ASCII lowercase letter to uppercase, leave all other characters unchanged, store the result, and output its zero-based insertion index.["SEARCH", deduplicate, keyword1, ...]: use case-sensitive literal-substring OR matching over stored logs. Visit logs in insertion order. Ifdeduplicateistrue, output each matching log once. If it isfalse, output the log once for each distinct input keyword it contains, in keyword-input order. Repeated keyword arguments count once.
The method returns one row per operation. A write row contains its insertion index as one decimal string. A search row contains its ordered matching logs.
Function
processLogs(operations: String[][]) → String[][]Examples
Example 1
operations = [["REMOVE","banana bandana","ana"],["CAPITALIZE","Mix 42"],["TRUNCATE","abcdef","3"],["SEARCH","true","A","band"],["SEARCH","false","a","b"]]return = [["0"],["1"],["2"],["bna band"],["bna band","bna band","abc","abc"]]Removing non-overlapping ana occurrences stores bna band. The deduplicated search returns it once. The non-deduplicated search emits it for both a and b, then emits abc for those two keywords.
Example 2
operations = [["CAPITALIZE","alpha"],["TRUNCATE","alphabet","5"],["REMOVE","aaaa","aa"],["SEARCH","true","alpha","ALP"],["SEARCH","false","a","aa"]]return = [["0"],["1"],["2"],["ALPHA","alpha"],["alpha"]]Search is case-sensitive. The empty stored log matches neither keyword. With deduplication disabled, lowercase alpha contains a but not aa.
Example 3
operations = [["TRUNCATE","hello","0"],["SEARCH","true","x"],["REMOVE","xxxyxx","xx"],["SEARCH","false","x","x","y"]]return = [["0"],[],["1"],["xy","xy"]]Truncating to zero stores an empty log. Removing xx left to right from xxxyxx stores xy. Repeated keyword x counts once, so xy is emitted for distinct keywords x and y.
Constraints
1 <= operations.length <= 10^4.- Logs, non-empty removal targets, and keywords contain at most
200printable ASCII characters. - Each truncation length is between
0and the corresponding input-log length. - Each search supplies at least one keyword. Its
deduplicatevalue istrueorfalse. - The sum of
stored log count * distinct keyword countacross all searches is at most2 * 10^5.
More Rippling problems
- Filter and Sort Scheduled TasksONSITE INTERVIEW · Seen Jul 2026
- Delivery Cost TrackerPHONE SCREEN · Seen Jul 2026
- Corporate Card Expense RulesPHONE SCREEN · Seen Jun 2026
- Camel CardsPHONE SCREEN · Seen May 2026
- Article Vote TrackerPHONE SCREEN · Seen May 2026
- Employee Resource Access ManagementONSITE INTERVIEW · Seen Jan 2026
- Limit an Organization Tree's HeightONSITE INTERVIEW · Seen Aug 2025
- Distributed System RecoveryOA · Seen Aug 2025