File tree 1 file changed +31
-0
lines changed
1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
1
+ def alternative_string_arrange (first_str : str , second_str : str ) -> str :
2
+ """
3
+ Return the alternative arrangements of the two strings.
4
+ :param first_str:
5
+ :param second_str:
6
+ :return: String
7
+ >>> alternative_string_arrange("ABCD", "XY")
8
+ 'AXBYCD'
9
+ >>> alternative_string_arrange("XY", "ABCD")
10
+ 'XAYBCD'
11
+ >>> alternative_string_arrange("AB", "XYZ")
12
+ 'AXBYZ'
13
+ >>> alternative_string_arrange("ABC", "")
14
+ 'ABC'
15
+ """
16
+ first_str_length : int = len (first_str )
17
+ second_str_length : int = len (second_str )
18
+ abs_length : int = (
19
+ first_str_length if first_str_length > second_str_length else second_str_length
20
+ )
21
+ output_list : list = []
22
+ for char_count in range (abs_length ):
23
+ if char_count < first_str_length :
24
+ output_list .append (first_str [char_count ])
25
+ if char_count < second_str_length :
26
+ output_list .append (second_str [char_count ])
27
+ return "" .join (output_list )
28
+
29
+
30
+ if __name__ == "__main__" :
31
+ print (alternative_string_arrange ("AB" , "XYZ" ), end = " " )
You can’t perform that action at this time.
0 commit comments