Solve theatre seating and ticker extraction
Company: Sig
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: This question evaluates algorithmic problem-solving skills across two areas: efficient seat-allocation and interval occupancy reasoning for grouping in a constrained seating layout, and robust string processing with phrase-based, case-insensitive matching and mapping to ticker identifiers.
Allocate 4-Person Groups in a Movie Theater
Constraints
- 1 <= row <= n (n can be 0, meaning no rows)
- seat values are between 1 and 10
- each seat is reserved at most once
- reserved pairs may be given in any order
Examples
Input: (1, [])
Expected Output: 2
Explanation: One empty row: take blocks 2-5 and 6-9 (disjoint) for 2 groups.
Input: (2, [])
Expected Output: 4
Explanation: Two empty rows, 2 groups each = 4.
Input: (1, [(1, 5)])
Expected Output: 1
Explanation: Seat 5 reserved kills blocks 2-5 and 4-7; only 6-9 remains.
Input: (1, [(1, 2), (1, 9)])
Expected Output: 1
Explanation: Seat 2 kills 2-5, seat 9 kills 6-9; only 4-7 survives.
Input: (1, [(1, 5), (1, 6)])
Expected Output: 0
Explanation: Seats 5 and 6 together block every candidate block.
Input: (3, [(1, 5), (2, 7), (3, 2)])
Expected Output: 3
Explanation: Row1->only 6-9 (1); Row2->only 2-5 (1); Row3->2-5 dead, 4-7 and 6-9 overlap so 1. Total 3.
Input: (0, [])
Expected Output: 0
Explanation: No rows, no groups.
Input: (1, [(1, 1), (1, 10)])
Expected Output: 2
Explanation: Seats 1 and 10 are outside every block, so 2-5 and 6-9 still fit: 2 groups.
Hints
- Only three candidate 4-seat blocks per row exist (2-5, 4-7, 6-9); a block is usable iff all four of its seats are free.
- Rows are independent, so solve each row separately and sum the results.
- Within a row, 2-5 and 6-9 are disjoint (giving 2 groups), but 4-7 overlaps both — pick the largest set of non-overlapping usable blocks.
Extract Stock Tickers From a News Headline
Constraints
- matching is case-insensitive and ignores punctuation
- matches are whole words/phrases, never substrings of a longer word
- each ticker appears at most once in the output
- tickers are ordered by first appearance in the headline
- at the same start position, the longer alias phrase is preferred
Examples
Input: ("Apple Inc. rises after Tesla delivery report", {"AAPL": ["apple", "apple inc"], "TSLA": ["tesla"]})
Expected Output: ["AAPL", "TSLA"]
Explanation: 'apple inc' is matched as the longer phrase at position 0; 'tesla' matched later.
Input: ("Tesla and Apple both gain; Tesla leads", {"AAPL": ["apple"], "TSLA": ["tesla"]})
Expected Output: ["TSLA", "AAPL"]
Explanation: Order follows first appearance; the second 'Tesla' is deduplicated.
Input: ("Pineapple sales drop", {"AAPL": ["apple"]})
Expected Output: []
Explanation: 'apple' inside 'pineapple' is a substring, not a whole word, so no match.
Input: ("APPLE INC announces record quarter", {"AAPL": ["apple inc", "apple"]})
Expected Output: ["AAPL"]
Explanation: Case-insensitive; longest phrase 'apple inc' wins, ticker listed once.
Input: ("No tickers here at all", {"AAPL": ["apple"], "TSLA": ["tesla"]})
Expected Output: []
Explanation: No alias appears.
Input: ("", {"AAPL": ["apple"]})
Expected Output: []
Explanation: Empty headline yields no matches.
Input: ("Microsoft, Google, and Amazon report earnings", {"MSFT": ["microsoft"], "GOOGL": ["google", "alphabet"], "AMZN": ["amazon"]})
Expected Output: ["MSFT", "GOOGL", "AMZN"]
Explanation: Three single-word matches in appearance order; punctuation ignored.
Input: ("Meta Platforms shares the spotlight with Meta", {"META": ["meta", "meta platforms"]})
Expected Output: ["META"]
Explanation: Longest phrase 'meta platforms' consumes both words at the start; the trailing 'meta' is a duplicate.
Hints
- Tokenize both the headline and every alias into lowercase alphanumeric words so punctuation and case stop mattering and whole-word matching is automatic.
- Index aliases by their tuple of words pointing to a ticker; track the longest alias length so you know how far ahead to look.
- Scan the headline left to right; at each position try the longest phrase first, and on a match advance past the consumed words to honor the longest-match-at-same-start rule.