Implement logger and card ranking
Company: Rippling
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Overview: This question evaluates API and system design, configurable string processing and state management for a logger (including search and complexity considerations), as well as algorithmic reasoning for card-hand ranking, sorting, and tie-breaking logic.
Read the full Rippling Software Engineer interview experience this question came from
Part 1: Simulate a Configurable Logger
Constraints
- 1 <= len(commands) <= 20000
- Each command is one of the formats described above
- Total length of all command strings is at most 200000
- SEARCH should be implemented case-sensitively
Examples
Input: ["SET_REMOVE ab", "SET_TRUNCATE 5", "SET_UPPERCASE 1", "SET_STORE 1", "LOG xxababy", "SEARCH Y"]
Expected Output: [["XXY"], ["XXY"]]
Explanation: After removal, truncation, and uppercase, 'xxababy' becomes 'XXY'. It is stored, and SEARCH Y finds it.
Input: ["SET_REMOVE", "SET_TRUNCATE -3", "LOG <NULL>", "SET_STORE 1", "LOG abcdef", "SEARCH"]
Expected Output: [[""], [""], [""]]
Explanation: Empty removal does nothing. Negative truncation becomes 0. '<NULL>' is treated as empty input. SEARCH with no query uses the empty string, so it matches every stored message.
Hints
- Keep four pieces of mutable state: removal substring, truncation length, uppercase flag, and store flag.
- Be careful with edge cases: empty removal string should not loop forever, and negative truncation should behave like length 0.
Part 2: Rank Custom Five-Card Hands
Constraints
- 1 <= len(records) <= 100000
- Each HAND has length exactly 5
- HAND contains only characters from 23456789TJQKA
- 0 <= BID <= 10^9
- Use 64-bit arithmetic in languages that need it
Examples
Input: ["32T3K 765", "T55J5 684", "KK677 28", "KTJJT 220", "QQQJA 483"]
Expected Output: 6440
Explanation: This is the standard sample for the non-wildcard rules.
Input: ["AAAAA 10"]
Expected Output: 10
Explanation: Edge case: a single hand always has rank 1.
Approach
Time complexity: O(n log n), where n is the number of records. The sort dominates; per-hand classification (Counter over exactly 5 cards) and key construction are O(1).
Space complexity: O(n) for the `parsed` list of sortable tuples (each holds a fixed 5-element rank list, so per-record space is constant).
Hints
- A hand's category depends only on the frequency counts of its 5 cards.
- For sorting, build a key like (category_strength, rank_of_card_1, rank_of_card_2, ..., rank_of_card_5).
Part 3: Rank Five-Card Hands with Wildcard Jokers
Constraints
- 1 <= len(records) <= 100000
- Each HAND has length exactly 5
- HAND contains only characters from 23456789TJQKA
- 0 <= BID <= 10^9
- Use 64-bit arithmetic in languages that need it
Examples
Input: ["32T3K 765", "T55J5 684", "KK677 28", "KTJJT 220", "QQQJA 483"]
Expected Output: 5905
Explanation: This is the standard sample for wildcard mode.
Input: ["JJJJJ 7"]
Expected Output: 7
Explanation: Edge case: all jokers become five of a kind, and the only hand gets rank 1.
Approach
Time complexity: O(n log n), where n is the number of records. Each hand is classified and keyed in O(1) (fixed 5 cards), and the dominant cost is sorting n hands.
Space complexity: O(n) for the parsed list of sort keys (each key holds a fixed-size 5-element rank list).
Hints
- Separate the number of J cards from the counts of the other ranks. If the hand is all J, it is automatically five of a kind.
- To maximize only the category, it is enough to add all jokers to the largest existing group. But for tie breaking, use the original hand with J as the lowest rank.
Community answers
Answer by m3ajak6
Answer by m3ajak6