Skip to content

Practice Transpose File

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#194
LeetCode Problem

Transpose File

Problem Statement

Read file.txt and transpose its space-separated table: each original column becomes an output row, retaining the original order of cells. Every input row has the same number of columns. Practice approach: In awk, accumulate one output string per column while reading rows, inserting spaces between cells. Print those strings in numeric column order at the end. Do not rely on hash-map iteration order. A rectangular two-row, three-column example exposes accidental assumptions that the input is square.

Source: Transpose File on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
a b c
d e f
Output
a d
b e
c f
Explanation

The three input columns become three output rows.

Constraints

All rows have the same number of columns.
Fields are separated by spaces.

Related LeetCode Problems

Practice more problems similar to Transpose File.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.