Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
ĐọcMethod #1 : Using loop This is brute force way in which this task can be performed. In this, we first split the string to words and then perform iteration to get the odd length words.
Python3
Bàn luận
Đôi khi, trong khi làm việc với Python, chúng ta có thể gặp vấn đề trong đó chúng ta cần trích xuất các từ dài nhất định từ một chuỗi. Đây có thể là trích xuất các từ dài lẻ từ chuỗi. Điều này có thể có ứng dụng trong nhiều lĩnh vực bao gồm lập trình hàng ngày. Hãy thảo luận về những cách nhất định trong đó nhiệm vụ này có thể được thực hiện. Phương pháp số 1: Sử dụng vòng lặp Đây là cách vũ phu trong đó nhiệm vụ này có thể được thực hiện. Trong đó, trước tiên chúng tôi chia chuỗi thành các từ và sau đó thực hiện lặp lại để có được các từ dài lẻ. & Nbsp;
test_str
=
"gfg is best of geeks"
print
[
"The original string is : "
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']0
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']1
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']2
=
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']4
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct7
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']5
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']7
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']8
The original string is : gfg is best of geeks
The odd length strings are : ['gfg', 'geeks']
9Input : arr[] = {"abcd", "cbad", "bacd"}
Output : 2
The 2nd string can be converted to the 1st by swapping
the first and third characters. So there are 2 distinct
0 Input : arr[] = {"abcd", "cbad", "bacd"}
Output : 2
The 2nd string can be converted to the 1st by swapping
the first and third characters. So there are 2 distinct
1Input : arr[] = {"abcd", "cbad", "bacd"}
Output : 2
The 2nd string can be converted to the 1st by swapping
the first and third characters. So there are 2 distinct
2223 Input : arr[] = {"abcd", "cbad", "bacd"}
Output : 2
The 2nd string can be converted to the 1st by swapping
the first and third characters. So there are 2 distinct
4 Input : arr[] = {"abcd", "cbad", "bacd"}
Output : 2
The 2nd string can be converted to the 1st by swapping
the first and third characters. So there are 2 distinct
5
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']
print
[
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 10
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']0
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 12
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 13Method #2 : Using list comprehension This task can also be performed using list comprehension. In this, we perform the task in similar way as above. Just the difference is that its a one-liner.
Python3
Bàn luận
Đôi khi, trong khi làm việc với Python, chúng ta có thể gặp vấn đề trong đó chúng ta cần trích xuất các từ dài nhất định từ một chuỗi. Đây có thể là trích xuất các từ dài lẻ từ chuỗi. Điều này có thể có ứng dụng trong nhiều lĩnh vực bao gồm lập trình hàng ngày. Hãy thảo luận về những cách nhất định trong đó nhiệm vụ này có thể được thực hiện. Phương pháp số 1: Sử dụng vòng lặp Đây là cách vũ phu trong đó nhiệm vụ này có thể được thực hiện. Trong đó, trước tiên chúng tôi chia chuỗi thành các từ và sau đó thực hiện lặp lại để có được các từ dài lẻ. & Nbsp;
test_str
=
"gfg is best of geeks"
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']5
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']7
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']8
The original string is : gfg is best of geeks
The odd length strings are : ['gfg', 'geeks']
9Input : arr[] = {"abcd", "cbad", "bacd"}
Output : 2
The 2nd string can be converted to the 1st by swapping
the first and third characters. So there are 2 distinct
0 Input : arr[] = {"abcd", "cbad", "bacd"}
Output : 2
The 2nd string can be converted to the 1st by swapping
the first and third characters. So there are 2 distinct
1Input : arr[] = {"abcd", "cbad", "bacd"}
Output : 2
The 2nd string can be converted to the 1st by swapping
the first and third characters. So there are 2 distinct
2223 Input : arr[] = {"abcd", "cbad", "bacd"}
Output : 2
The 2nd string can be converted to the 1st by swapping
the first and third characters. So there are 2 distinct
4 Input : arr[] = {"abcd", "cbad", "bacd"}
Output : 2
The 2nd string can be converted to the 1st by swapping
the first and third characters. So there are 2 distinct
5
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']
print
[
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 10
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']0
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 12
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 13
Đầu ra: & nbsp;O[n]
& nbsp; Phương pháp số 2: Sử dụng danh sách Hiểu biết Nhiệm vụ này cũng có thể được thực hiện bằng cách sử dụng danh sách hiểu. Trong đó, chúng tôi thực hiện nhiệm vụ theo cách tương tự như trên. Chỉ là sự khác biệt là nó là một lớp lót. & NBSP;O[n]
Với một loạt các chuỗi chữ thường, nhiệm vụ là tìm số lượng chuỗi khác biệt. Hai chuỗi là khác biệt nếu, khi áp dụng các hoạt động sau trên một chuỗi, chuỗi thứ hai không thể được hình thành. & Nbsp; & nbsp;
- Một ký tự trên chỉ số lẻ chỉ có thể được hoán đổi với một ký tự khác trên chỉ số lẻ.
- Một ký tự trên chỉ mục có thể được hoán đổi với một ký tự khác chỉ trên chỉ mục.
Examples:
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 1
Một giải pháp đơn giản là chạy hai vòng. Vòng lặp bên ngoài chọn một chuỗi và vòng lặp bên trong kiểm tra xem có chuỗi trước đó có thể được chuyển đổi thành chuỗi hiện tại bằng cách thực hiện các phép biến đổi được phép. Giải pháp này yêu cầu thời gian O [N2M] trong đó n là số chuỗi và M là số lượng ký tự tối đa trong bất kỳ chuỗi nào.simple solution is to run two loops. The outer loop picks a string and the inner loop checks if there is a previously string which can be converted to a current string by doing allowed transformations. This solution requires O[n2m] time where n is the number of strings and m is the maximum number of characters in any string.
Một giải pháp hiệu quả tạo ra một chuỗi được mã hóa cho mỗi chuỗi đầu vào. Các mã được mã hóa có số lượng các ký tự được định vị chẵn và lẻ được phân tách bằng một dấu phân cách. Hai chuỗi được coi là giống nhau nếu các chuỗi được mã hóa của chúng giống nhau, thì khác thì không. Khi chúng ta có một cách để mã hóa các chuỗi, vấn đề sẽ được giảm xuống để đếm các chuỗi được mã hóa riêng biệt. Đây là một vấn đề điển hình của băm. Chúng tôi tạo một bộ băm và, từng cái một, lưu trữ mã hóa của chuỗi. Nếu một mã hóa đã tồn tại, chúng ta bỏ qua chuỗi. Mặt khác, chúng tôi lưu trữ mã hóa trong băm và số lượng tăng của các chuỗi riêng biệt. & Nbsp;efficient solution generates an encoded string for every input string. The encoded has counts of even and odd positioned characters separated by a separator. Two strings are considered same if their encoded strings are the same, then else not. Once we have a way to encode strings, the problem is reduced to counting distinct encoded strings. This is a typical problem of hashing. We create a hash set and, one by one, store encodings of strings. If an encoding already exists, we ignore the string. Otherwise, we store encoding in hash and increment count of distinct strings.
Implementation:
C++
"gfg is best of geeks"
1
"gfg is best of geeks"
2 "gfg is best of geeks"
3 "gfg is best of geeks"
4
"gfg is best of geeks"
5 "gfg is best of geeks"
6
"gfg is best of geeks"
7"gfg is best of geeks"
8 "gfg is best of geeks"
9"gfg is best of geeks"
5 print
1
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
"gfg is best of geeks"
5 print
4The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
"gfg is best of geeks"
5 print
7The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
print
9[
0[
1[
2The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
print
9[
5[
1[
7The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']5
[
"gfg is best of geeks"
5 "The original string is : "
2Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
"gfg is best of geeks"
8 "The original string is : "
5Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct0
"The original string is : "
8"The original string is : "
9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']00
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']01
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']02
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']04
"The original string is : "
9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']06
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']01
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']02
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']10
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']12
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']13
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']14
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']5
[
"gfg is best of geeks"
5 The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']19
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']21
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']23
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']24
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']25
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']27
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']23
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']24
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']25
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']10
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']35
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']36
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']10
"gfg is best of geeks"
5
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']39
"gfg is best of geeks"
5 The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']41
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
"gfg is best of geeks"
5 The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']44
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']46
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']5
[
"gfg is best of geeks"
5 The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']51
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
"gfg is best of geeks"
8 The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']54
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']56
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']57
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct0
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']60
"The original string is : "
9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']62
"The original string is : "
9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']64
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']10
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']10
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']35
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']71
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']10
"gfg is best of geeks"
5
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']74
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']76
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']77
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']78
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']79
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']78
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']81
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']78
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']83
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']84
"The original string is : "
9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']86
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']78
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']88
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']89
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
"gfg is best of geeks"
5 The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']92
[
1The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']94
[
1The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']96
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']98
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']99
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']14
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']10
Java
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct02
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct03
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct02
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct05
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct06
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct07
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct08
"gfg is best of geeks"
5 Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct10
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct11
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']14
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct08
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct15
"gfg is best of geeks"
8Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct17
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
"gfg is best of geeks"
5 Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct20
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct21
"gfg is best of geeks"
5Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct23
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
"gfg is best of geeks"
5 Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct26
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct21
"gfg is best of geeks"
5Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct23
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']5
[
"gfg is best of geeks"
5 Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct34
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct35
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct36
"The original string is : "
9"gfg is best of geeks"
8 "The original string is : "
5
"The original string is : "
9
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct0
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct42
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct43
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct444____235
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct46
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct47
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']00
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']01
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']02
"The original string is : "
9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']04
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct47
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']06
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']01
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']02
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']10
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct60
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']13
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']14
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']5
[
"gfg is best of geeks"
5 Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct34
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct35
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct69
"The original string is : "
9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']21
"The original string is : "
9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']23
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']24
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']25
"The original string is : "
9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']27
"The original string is : "
9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']23
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']24
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']25
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']10
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']35
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']36
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']10
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct08
"gfg is best of geeks"
5 Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct92
"gfg is best of geeks"
5 The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']41
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
"gfg is best of geeks"
5 Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct97
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct35
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct99
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 101
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct21
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 103
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']5
[
"gfg is best of geeks"
5 Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct34
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct35
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 110
"The original string is : "
9
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct0
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 113
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct47
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 115
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct47
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']64
"The original string is : "
9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']10
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']10
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']35
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']71
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']10
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 128
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct08
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 130
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 131
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 133
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']77
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']78
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']79
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']78
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']81
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']78
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']83
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']84
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct47
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']86
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']78
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']88
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']89
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
"gfg is best of geeks"
5 strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 149
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 151
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']10
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']10
Python3
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 155
=
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct11
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 158
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 159
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 161
=
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 163
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct35
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 165
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 166
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 167
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 169
=
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 163
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct35
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 165
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 166
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 167
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']5
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 178
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']7
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 180
[
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct1
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 183
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 185
=
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 187
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct0
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 190
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct43
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 192
"The original string is : "
9
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 194
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 195
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 196______397
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']04
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct5
"The original string is : "
9test_str
09
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 195
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 196______397
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
test_str
21=
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']13
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']5
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 178
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']7
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 180
test_str
29Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
test_str
21The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']0
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 12
test_str
35Các
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
test_str
21The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']0
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 12
test_str
49Các
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
test_str
21The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']0
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 12
test_str
49The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']35
test_str
60strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 158
test_str
62test_str
63test_str
64The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
test_str
66=
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct35
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
test_str
70=
test_str
72test_str
73The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']5
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 178
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']7
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 180
test_str
79"The original string is : "
9test_str
89test_str
63test_str
91
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct0
test_str
82test_str
63__"The original string is : "
9test_str
66____10105
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct43
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']35
test_str
99Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct0
=
01=
=
=
04Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct5
=
16
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']83
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']78
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']86
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']78
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']88
=
4The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
test_str
63 =
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 163
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']77
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']78
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']79
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']78__
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
print
=
32test_str
63=
34C#
"gfg is best of geeks"
2 =
36
"gfg is best of geeks"
2 =
38
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct06
=
40=
41
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct08
"gfg is best of geeks"
5 "gfg is best of geeks"
6The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct08
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct15
"gfg is best of geeks"
8=
50The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
=
41Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
"gfg is best of geeks"
5 =
55Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct21
"gfg is best of geeks"
5Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct23
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
"gfg is best of geeks"
5 =
61Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct21
"gfg is best of geeks"
5Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct23
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']5
[
"gfg is best of geeks"
5 =
69Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
=
41"The original string is : "
9"gfg is best of geeks"
8 =
74
"The original string is : "
9
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct0
=
77Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct47
=
79The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']01
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']02
"The original string is : "
9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']04
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct47
=
85The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']01
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']02
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']10
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct60
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']13
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']14
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']5
[
"gfg is best of geeks"
5 =
98Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
=
41"The original string is : "
9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']21
"The original string is : "
9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']23
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']24
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']25
"The original string is : "
9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']27
"The original string is : "
9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']23
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']24
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']25
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']10
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']35
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']36
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']10
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct08
"gfg is best of geeks"
5 "gfg is best of geeks"
23"gfg is best of geeks"
5 "gfg is best of geeks"
25The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
=
41Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
"gfg is best of geeks"
5 The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']44
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
"gfg is best of geeks"
32Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct21
"gfg is best of geeks"
34Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']5
[
"gfg is best of geeks"
5 "gfg is best of geeks"
39Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
=
41"The original string is : "
9
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct0
"gfg is best of geeks"
44"The original string is : "
9=
41
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct47
"gfg is best of geeks"
48Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct47
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']64
"The original string is : "
9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']10
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']10
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']35
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']71
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']10
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 128
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct08
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 130
"gfg is best of geeks"
64The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
=
41Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
"gfg is best of geeks"
68The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']77
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']78
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']79
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']78
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']81
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']84
"gfg is best of geeks"
75
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']83
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']78
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']86
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']78
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']88
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']89
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
"gfg is best of geeks"
5 "gfg is best of geeks"
84Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
"gfg is best of geeks"
86The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']10
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']10
JavaScript
"gfg is best of geeks"
90
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
"gfg is best of geeks"
92The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
"gfg is best of geeks"
94 "gfg is best of geeks"
95Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
"gfg is best of geeks"
97Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
"gfg is best of geeks"
99Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']5
print
02"The original string is : "
9print
04
"The original string is : "
9
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct0
"The original string is : "
8Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct47
print
09The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']01
print
11"The original string is : "
9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']04
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct47
print
15The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']01
print
11Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']10
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
print
21The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']13
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']14
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']5
print
26"The original string is : "
9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']21
"The original string is : "
9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']23
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']24
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']25
"The original string is : "
9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']27
"The original string is : "
9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']23
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']24
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']25
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']10
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']35
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']36
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']10
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct08
"gfg is best of geeks"
5 "gfg is best of geeks"
23"gfg is best of geeks"
5 "gfg is best of geeks"
25Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
print
50Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
"gfg is best of geeks"
5 The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']44
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
"gfg is best of geeks"
32Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct21
"gfg is best of geeks"
34Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']5
[
"gfg is best of geeks"
5 "gfg is best of geeks"
39Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct47
print
64print
61print
66Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct47
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']64
"The original string is : "
9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']10
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']10
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']35
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']71
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']10
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
print
79The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']77
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']78
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']79
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']78
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']81
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']78
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']83
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']84
The original string is : gfg is best of geeks The odd length strings are : ['gfg', 'geeks']9
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 128
Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct08
strings as the third string cannot be converted to the first. Input : arr[] = {"abc", "cba"} Output : 130
"gfg is best of geeks"
64Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
print
94Input : arr[] = {"abcd", "cbad", "bacd"} Output : 2 The 2nd string can be converted to the 1st by swapping the first and third characters. So there are 2 distinct6
print
96print
97
Input : arr[] = {"abcd", "cbad", "bacd"}
Output : 2
The 2nd string can be converted to the 1st by swapping
the first and third characters. So there are 2 distinct
6"gfg is best of geeks"
5 "gfg is best of geeks"
84: O[n]
Auxiliary Space : O[1]
JavaScript