PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates a candidate's ability to serialize and format in-memory data structures for deterministic textual output, focusing on representation of ordered collections and correct handling of empty versus non-empty blocks.

  • medium
  • Anchorage
  • Coding & Algorithms
  • Software Engineer

Print the File System State

Company: Anchorage

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given a toy in-memory file system represented as an ordered sequence of disk blocks. Each block contains zero or more file records, such as file names or identifiers. Implement a `print()` or `toString()` method that displays the entire current state of the file system. Requirements: - Print blocks in their current order. - Represent each block using square brackets. - An empty block should be printed as `[]`. - Non-empty blocks should print their contents inside the brackets, separated by commas. - Consecutive blocks should be connected with ` -> `. - Do not print a trailing arrow. Example: A file system with three empty blocks should print: ```text [] -> [] -> [] ``` A file system with blocks containing `['a.txt']`, `[]`, and `['b.txt', 'c.txt']` should print: ```text [a.txt] -> [] -> [b.txt, c.txt] ```

Quick Answer: This question evaluates a candidate's ability to serialize and format in-memory data structures for deterministic textual output, focusing on representation of ordered collections and correct handling of empty versus non-empty blocks.

You are given a toy in-memory file system represented as an ordered sequence of disk blocks. Each block contains zero or more file records, represented as strings such as file names or identifiers. Implement a function that returns a string displaying the entire current state of the file system. Blocks must be shown in their current order. Each block is enclosed in square brackets. Empty blocks are represented as []. Non-empty blocks contain their records separated by commas and spaces. Consecutive blocks are connected with " -> ". Do not include a trailing arrow. If there are no blocks, return an empty string.

Constraints

  • 0 <= number of blocks <= 10^4
  • 0 <= number of records in each block <= 10^3
  • The total number of records across all blocks is at most 10^5
  • Each file record is a non-empty string containing only printable characters and does not contain commas or square brackets

Examples

Input: ([[], [], []],)

Expected Output: '[] -> [] -> []'

Explanation: There are three empty blocks, so each is printed as [] and connected with arrows.

Input: ([['a.txt'], [], ['b.txt', 'c.txt']],)

Expected Output: '[a.txt] -> [] -> [b.txt, c.txt]'

Explanation: The first block contains one file, the second block is empty, and the third block contains two files separated by a comma and space.

Input: ([],)

Expected Output: ''

Explanation: There are no blocks in the file system, so the formatted state is an empty string.

Input: ([['root', 'config'], ['log']],)

Expected Output: '[root, config] -> [log]'

Explanation: Both blocks are non-empty and are printed in order without a trailing arrow.

Input: ([['file1']],)

Expected Output: '[file1]'

Explanation: A single non-empty block is printed by itself with no arrow.

Hints

  1. Format each block independently first, then combine the block strings.
  2. Use string joining instead of repeatedly concatenating in a loop for better efficiency.
Last updated: Jun 13, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ 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.