-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathTransfiguration.cpp
More file actions
45 lines (39 loc) · 817 Bytes
/
Transfiguration.cpp
File metadata and controls
45 lines (39 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//{ Driver Code Starts
#include<bits/stdc++.h>
using namespace std;
// } Driver Code Ends
class Solution{
public:
int transfigure (string A, string B)
{
// Your code goes here
int arr[256]={};
if(A.size()!=B.size()) return -1;
for(int i=0;i<A.size();i++) {
arr[A[i]]++;
arr[B[i]]--;
}
for(int i=0;i<256;i++) if(arr[i]) return -1;
int j=B.size()-1, res=0, i=A.size()-1;
while(i>=0) {
if(A[i]==B[j]) {i--; j--;}
else {res++; i--;}
}
return res;
// ABCD
// DBAC
}
};
//{ Driver Code Starts.
int main ()
{
int t; cin >> t;
while (t--)
{
string A, B;
cin >> A >> B;
Solution obj;
cout << obj.transfigure (A, B) << endl;
}
}
// } Driver Code Ends