Solve Signature, File, and Queue Problems
Company: Confluent
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: This multi-part prompt evaluates skills in function signature and type matching, resource-constrained file I/O and streaming for large files, and data-structure design for randomized queues including multiset equality, synchronization, and compact run-length encodings.
Part 1: Function Signature Matching
Constraints
- 0 <= len(functions) <= 200
- 0 <= len(call_args) <= 2000
- The total number of parameters across all functions is at most 4000
- Each function has at most one 'variadic' parameter, and if present it is the last parameter
- Type names are case-sensitive strings
Examples
Input: ([[('int', 'required'), ('str', 'optional'), ('bool', 'required')]], ['int', 'bool'])
Expected Output: True
Explanation: The optional 'str' parameter is skipped, so the call matches (int, bool).
Input: ([[('int', 'required'), ('str', 'variadic')], [('int', 'required'), ('bool', 'required')]], ['int', 'str', 'str'])
Expected Output: True
Explanation: The first function matches: required int, then two variadic str arguments.
Input: ([[('int', 'optional')], []], [])
Expected Output: True
Explanation: The empty function signature matches an empty call.
Input: ([[('int', 'required'), ('str', 'optional'), ('bool', 'required')], [('float', 'required')]], ['int', 'str'])
Expected Output: False
Explanation: The first function is still missing the final required bool, and the second expects a float.
Input: ([[('int', 'optional'), ('int', 'required')]], ['int'])
Expected Output: True
Explanation: A correct solution must skip the optional int and use the required int; always consuming matching optionals would fail here.
Hints
- Because optional parameters can be skipped, a greedy left-to-right match may fail. Think about states based on both the parameter index and the argument index.
- If you reach a trailing variadic parameter, the rest of the arguments must all have that variadic type.
Part 2: Last N Lines of a Large File
Constraints
- 0 <= len(file_text) <= 10^6
- 0 <= n <= 10^5
- Lines are separated only by the newline character '\n'
- The returned list stands in for streamed stdout output in this testable version
Examples
Input: ('a\nb\nc\n', 2)
Expected Output: ['b', 'c']
Explanation: The trailing newline does not add an extra empty line, so the last two lines are b and c.
Input: ('one\ntwo\nthree', 5)
Expected Output: ['one', 'two', 'three']
Explanation: If n is larger than the number of lines, return all available lines.
Input: ('', 3)
Expected Output: []
Explanation: An empty file has no lines.
Input: ('\n\nx\n', 3)
Expected Output: ['', '', 'x']
Explanation: There are two empty lines before x.
Input: ('single line', 0)
Expected Output: []
Explanation: Requesting zero lines should return an empty list.
Hints
- You only need to find the boundaries of the last n lines, so scanning from the end is natural.
- Be careful with a trailing newline: it ends the final line but should not count as a new empty line after it.
Part 3: Random Queue Equality with Run-Length Encoding
Constraints
- 0 <= len(queue_a), len(queue_b) <= 2 * 10^5
- 1 <= count <= 10^12
- Values are integers in the range [-10^9, 10^9]
- Do not assume the same value appears in only one run
Examples
Input: ([(1, 2), (2, 1), (1, 3)], [(2, 1), (1, 5)])
Expected Output: True
Explanation: Both queues contain five 1s and one 2.
Input: ([(5, 1)], [])
Expected Output: False
Explanation: One queue contains a 5 and the other is empty.
Input: ([], [])
Expected Output: True
Explanation: Two empty queues are equal.
Input: ([(-1, 2), (3, 1)], [(3, 1), (-1, 1), (-1, 1)])
Expected Output: True
Explanation: The same value may appear in multiple runs; totals still match.
Input: ([(7, 1000000000000)], [(7, 999999999999), (8, 1)])
Expected Output: False
Explanation: The total counts differ because the second queue has an 8 instead of one of the 7s.
Hints
- Since queue equality is based on a multiset, order does not matter; multiplicities do.
- Comparing runs position-by-position is incorrect. Aggregate total counts per value.