MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / Solution

Class Solution

StringTransformationByInsertingAtFront.java:1–37  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class Solution
2{
3 int transform (String A, String B)
4 {
5 // code here
6 if(A.length()!=B.length()) return -1;
7 int arr[] = new int[256];
8 for(int i=0;i<A.length();i++)
9 {
10 arr[A.charAt(i)]++;
11 arr[B.charAt(i)]--;
12 }
13
14 for(int i=0;i<256;i++)
15 {
16 if(arr[i]!=0) return -1;
17 }
18
19 int res=0;
20 int p1 = A.length()-1;
21 int p2 = B.length()-1;
22
23 while(p1>=0)
24 {
25 if(A.charAt(p1)!=B.charAt(p2))
26 {
27 res++;
28 }
29 else
30 {
31 p2--;
32 }
33 p1--;
34 }
35 return res;
36 }
37}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected