1
// samll trick: for plaindrome question always try to follow concept that if
2
// corners are equal we need to only work on middle string to check whether it
3
// is also palindrome, instead of check complete strings(both given strings).
4
class Solution {
5
public:
6
bool ispalind(string x, int i, int j) {
7
while (i < j) {
8
if (x[i] != x[j]) return false;
9
i++;
10
j--;
11
}
12
return true;
13
}
14
bool checkpositions(string a, string b) {
15
int i = 0, j = b.size() - 1;
16
while (i < j) {
17
if (a[i] != b[j]) break;
18
i++;
19
j--;
20
}
21
/*
22
left cut
23
//agar same hote toh
24
"ulacfd" ul.zalu //to check for palindrome : za(from b)
25
"jizalu" ji.acfd //to check for palindrome : ac(from a)
26
*/
27
/*
28
right cut
29
//agar samee hote toh
30
"ulacfd" jiza.fd //to check for palindrome : za(from b)
31
"jizalu" ulac.lu //to check for palindrome : ac(from a)
32
*/
33
return ispalind(a, i, j) || ispalind(b, i, j);
34
}
35
bool checkPalindromeFormation(string a, string b) {
36
// cut one(from left) //cut two(from right)
37
return checkpositions(a, b) || checkpositions(b, a);
38
}
39
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0