Playing Hacks and Stuffs!
Here’s is my thought process while I was trying to solve it:
i
and j
such that j - i = 2
, then if that works we will swap the two characters at those indices in the stringSolve Script: link
This is the idea behind my solve script:
First I figured that from the constraint the length of the string will be always 4
Then if I’m to find two indices such that j - i = 2
therefore the value of j
would be always greater than i
And from the length of the string there can be only two ways for us to meet that conditio
What that means is that at index 0
and 2
or 3
and 1
is that index value which would always meet that condition
Now for the swapping part what I did was to find all the values that can be swapped from the two possiblities
Then I’ll the swapped value again
I just did that twice because I noticed upon swapping three times it would likely return it’s initial value
So then I check if the second string is among the list of swapped values and if it is then I return True else False
The script works but it isn’t quite efficient