apple

Finished
11def transpose(text: str) -> str:
2 pass
2 # Edge Case: Empty input
3 if not text:
4 return ""
5
6 # Split the input text into lines
7 lines = text.split('\n')
8
9 # Edge Case: Single line or empty lines only
10 if len(lines) == 1:
11 return '\n'.join(lines[0]) if lines[0] else ""
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 ""
19
20 # Pad each line to the maximum length with spaces on the right
21 padded_lines = [line.ljust(max_length) for line in lines]
22
23 # Transpose the matrix
24 transposed = []
25 for col in range(max_length):
26 new_row = ''.join(padded_lines[row][col] for row in range(len(padded_lines)))
27 transposed.append(new_row)
28
29 # Remove trailing spaces from each row but preserve leading spaces
30 result_lines = []
31 for line in transposed:
32 # Edge Case: Line with only spaces
33 if line.strip() == "":
34 result_lines.append(line.rstrip())
35 else:
36 result_lines.append(line.rstrip())
37
38 return '\n'.join(result_lines)
39
40# Handled Edge Cases: Empty input, Single line or empty lines only, All lines are empty, Line with only spaces
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.