i am stucked in this problem can any one give me an idea ..
he problem is this..
You are given two strings. Write an algorithm that creates a third string such that it contains both the given strings and it should be the smallest possible string. There is no condition regarding order of occurrence of given strings in the third string. Implement your algorithm in C++ using classes.
S2 = “loot”
S3 = “helloloot” //Incorrect as S3 is not the smallest possible string
b) S1= “hello”
S2 = “Delhi”
S3 = “helloDelhi” or “Delhihello”
so if you have the string "hello" and the string "loot" it would become "helloot" since the ending "lo" of hello and the beginning "lo" of loot are the same? and "helloeDelhi" hase no over lap so it isnt truncated correct?
This might get you started.
There are 2 string: stringA= hellow , stringB= owl
So what you got to do is take the first character of string B and iterate it over stringA from the ending. In this case, we take the character o from stringB and compare it with w
It does not match so move ahead to o. This one does match. So now you compare the 2 character of stringB that is w
Did you get the logic ?
thank you both of you
i got it :)