PracHub
QuestionsPremiumLearningGuidesCheatsheetNEW
|Home/Coding & Algorithms/Confluent

Implement Tail and Find Monster Cost

Last updated: May 6, 2026

Quick Overview

This question evaluates competency in efficient file I/O and streaming techniques for implementing tail, and in graph search and shortest-path algorithms with path reconstruction for computing minimum monster cost in a grid.

  • medium
  • Confluent
  • Coding & Algorithms
  • Software Engineer

Implement Tail and Find Monster Cost

Company: Confluent

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

This entry contains two coding tasks from the same interview category. ### Task A: Implement a file tail operation Implement a function `tail(filePath, n)` that returns the last `n` lines of a text file in their original order. Requirements: - The input is a real file path, not an in-memory string. You should be comfortable creating a small text file as a test case and reading it back. - If the file has fewer than `n` lines, return all lines. - If `n == 0`, return an empty result. - A trailing newline at the end of the file should not create an extra empty line. - Discuss or implement an approach that does not load the entire file into memory when the file is very large. ### Task B: Find minimum monster cost in a grid You are given a 2D grid representing a dungeon: - `S` is the start cell. - `E` is the exit cell. - `.` is an empty cell with cost `0`. - `M` is a monster cell with cost `1` to enter. - `#` is a wall that cannot be entered. From any cell, you may move up, down, left, or right. Return the minimum total monster cost required to travel from `S` to `E`. If the exit is unreachable, return `-1`. Follow-ups: - Return one path that achieves the minimum cost. - Extend the grid so each monster cell has an arbitrary non-negative integer cost instead of cost `1`.

Quick Answer: This question evaluates competency in efficient file I/O and streaming techniques for implementing tail, and in graph search and shortest-path algorithms with path reconstruction for computing minimum monster cost in a grid.

Related Interview Questions

  • Solve Signature, File, and Queue Problems - 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)
Confluent logo
Confluent
Apr 29, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
0
0

This entry contains two coding tasks from the same interview category.

Task A: Implement a file tail operation

Implement a function tail(filePath, n) that returns the last n lines of a text file in their original order.

Requirements:

  • The input is a real file path, not an in-memory string. You should be comfortable creating a small text file as a test case and reading it back.
  • If the file has fewer than n lines, return all lines.
  • If n == 0 , return an empty result.
  • A trailing newline at the end of the file should not create an extra empty line.
  • Discuss or implement an approach that does not load the entire file into memory when the file is very large.

Task B: Find minimum monster cost in a grid

You are given a 2D grid representing a dungeon:

  • S is the start cell.
  • E is the exit cell.
  • . is an empty cell with cost 0 .
  • M is a monster cell with cost 1 to enter.
  • # is a wall that cannot be entered.

From any cell, you may move up, down, left, or right. Return the minimum total monster cost required to travel from S to E. If the exit is unreachable, return -1.

Follow-ups:

  • Return one path that achieves the minimum cost.
  • Extend the grid so each monster cell has an arbitrary non-negative integer cost instead of cost 1 .

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Confluent•More Software Engineer•Confluent Software Engineer•Confluent Coding & Algorithms•Software Engineer Coding & Algorithms
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.