PracHub
QuestionsPremiumLearningGuidesCheatsheetNEW

Quick Overview

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.

  • medium
  • Confluent
  • Coding & Algorithms
  • Software Engineer

Solve Signature, File, and Queue Problems

Company: Confluent

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Solve the following interview-style problems: 1. **Function signature matching** You are given a registry of function definitions. Each function has an ordered parameter list where parameters may be **required**, **optional**, or a trailing **variadic** parameter. Given a candidate call signature represented as an ordered list of argument types, determine whether at least one registered function can accept the call. Assume exact type matching and no implicit coercions. 2. **Print the last N lines of a large file** Implement a utility that prints the last `N` lines of a file to `stdout`. The file may be much larger than memory, so the solution should avoid loading the entire file. Discuss tradeoffs between scanning with fixed-size buffers versus seeking backward with file offsets. Then write pseudocode using only the following file API: - `size() -> int` - `read(k) -> bytes` from the current file pointer, advancing the pointer - `move(delta)` to shift the file pointer forward or backward by `delta` bytes The final output must be streamed to `stdout` rather than first materializing the full answer in memory. 3. **Random queue** Design a queue-like data structure that supports insertion but returns or removes a uniformly random existing element instead of the oldest element. Then discuss: - how to determine whether two such queues are equal, - what synchronization and correctness issues arise in a multithreaded implementation, - and how equality checking changes if the queue contents are stored using variable-length run-length encoding. Assume equality means the two queues represent the same multiset of values, regardless of internal storage layout.

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

You are given a registry of function definitions and a candidate call signature. Each function definition is an ordered list of parameters, where every parameter is one of: required, optional, or variadic. Optional parameters may appear anywhere before the variadic parameter. A variadic parameter, if present, is always the last parameter and may match zero or more trailing arguments of exactly the same type. Determine whether at least one registered function can accept the given call. Matching is positional, exact, and does not allow type coercion.

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

  1. 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.
  2. 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

Implement a tail-like utility. For testing, the file is provided as a single string file_text, where lines are separated by '\n'. Return the last N lines in their original order, without newline characters. If the text ends with a trailing '\n', that newline terminates the last line and does not create an extra empty line by itself. Empty lines inside the file are valid lines. Aim for a solution that scans backward from the end rather than splitting the entire file into all lines first.

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

  1. You only need to find the boundaries of the last n lines, so scanning from the end is natural.
  2. 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

A random queue removes a uniformly random stored element, so its logical state is determined only by the multiset of stored values, not by insertion order or internal layout. You are given two queue states, each stored using run-length encoding as a list of (value, count) pairs. The same value may appear in multiple runs, and runs may be arranged differently in the two queues. Determine whether the two queues represent the same multiset of values without fully expanding the runs.

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

  1. Since queue equality is based on a multiset, order does not matter; multiplicities do.
  2. Comparing runs position-by-position is incorrect. Aggregate total counts per value.
Last updated: May 6, 2026

Loading coding console...

PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Implement Tail and Find Monster Cost - Confluent (medium)
  • Process pod logs with global increments and pop-min - Confluent (easy)
  • Implement File Tail and Sensor Health - Confluent (medium)
  • Rank songs by pairwise user preferences - Confluent (medium)
  • Implement tail N lines - Confluent (Medium)