We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
If any 1 is having problem in understanding case B
all he meant is as below:
eg:-
s=hackerrank
t=hackerearth
k=11
len(s)+len(t)=10+11=21
commonlenghth=6
21-2*6=21-12=9
s=hackerrank->hacker
moves performed =4
moves left=11-4=7
to make s(hacker)->t(hackerearth) we require 5 more moves to append "earth" but we have 7-5 =2
i.e we have 2 extra move so we use this move as to delete and append the same character as follows :
and hence if we had an even number we would not have been able to perform this operation
the same will be the case if we had an even string and even value of k
hope my exlanation helps someone in need.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Append and Delete
You are viewing a single comment's thread. Return to all comments →
If any 1 is having problem in understanding case B all he meant is as below:
eg:-
s=hackerrank
t=hackerearth
k=11
len(s)+len(t)=10+11=21
commonlenghth=6
21-2*6=21-12=9
s=hackerrank->hacker
moves performed =4
moves left=11-4=7
to make s(hacker)->t(hackerearth) we require 5 more moves to append "earth" but we have 7-5 =2 i.e we have 2 extra move so we use this move as to delete and append the same character as follows :
s=hacker->hacke->hacker->hackerearth
explanation=(original)->(deleted "r")->(appended "r")->(appended "earth")
moves=7
and hence if we had an even number we would not have been able to perform this operation the same will be the case if we had an even string and even value of k
hope my exlanation helps someone in need.