1

This might be a kind of confusion application.

So imagine having two strings, one is a larger string which will be parsed through, and the other is a smaller string which we will use to search the for matching characters in the larger string.

I need to find the letters which match AND keep the relative order of the larger text.

Strings:

larger_txt = "absdfgdsfhsrbbfsdc"

smaller_txt = "dsdfbdfdef"

Output should be (from larger_txt): "sdfbfd"

So the longest is length of 6.

It is the longest string that keeps the relative order from both the larger_txt and smaller_txt.

For example,

the 'd' in the smaller_txt is at index '0', and the first 'd' in the larger_txt is at index '3'. So at this point the larger and smaller at consecutive. Then we look for 's', we see 's' but it's at index 2 in the larger, so that doesn't fit because it comes before the previous 'd' at index 3, so we even though it is there we have to use the one after. See the problem?

My question is how do I sort things around so that each char has a weight and organize it in such a way that the letters that are the MOST consecutive with the largest weight gets picked out?

Thanks

  • I would take answer from https://stackoverflow.com/questions/18715688/find-common-substring-between-two-strings and adapt it with some weight for each char, that is, the len() functions to keep track of the winner will become your weight function. Let me know if example needed – Willem Hendriks Oct 03 '21 at 21:35

0 Answers0