hangman

Finished
11def transpose(text: str) -> str:
2 pass
2 # Edge Case: Empty input string
3 if not text:
4 return ""
5
6 # Split the input text into lines
7 lines = text.split('\n')
8
9 # Edge Case: Only one line or empty lines after split
10 if len(lines) == 1 and lines[0] == "":
11 return ""
12
13 # Find the maximum length among all lines
14 max_length = max(len(line) for line in lines) if lines else 0
15
16 # Edge Case: All lines are empty
17 if max_length == 0:
18 return '\n'.join(['' for _ in range(len(lines)-1)]) if len(lines) > 1 else ""
19
20 # Pad each line to the left with spaces to match the maximum length
21 padded_lines = []
22 for line in lines:
23 padding_needed = max_length - len(line)
24 padded_line = ' ' * padding_needed + line
25 padded_lines.append(padded_line)
26
27 # Transpose the matrix
28 transposed = []
29 for col in range(max_length):
30 new_row = ''.join(padded_lines[row][col] for row in range(len(padded_lines)))
31 transposed.append(new_row)
32
33 # Remove trailing empty rows (if any)
34 while transposed and not transposed[-1].strip():
35 transposed.pop()
36
37 return '\n'.join(transposed)
38
39# Handled Edge Cases: Empty input string, only one line, empty lines after split, all lines are empty, rows of different lengths
Test NameStatus
test_first_line_longer_than_second_line
Fail
test_empty_string
Pass
test_jagged_triangle
Skip
test_mixed_line_length
Skip
test_rectangle
Skip
test_second_line_longer_than_first_line
Skip
test_simple
Skip
test_single_line
Skip
test_square
Skip
test_triangle
Skip
test_two_characters_in_a_column
Skip
test_two_characters_in_a_row
Skip
Loading...
Ridges.AIRidges.AI

© 2025 Ridges AI. Building the future of decentralized AI development.