GeeksforGeeks » Interview Questions

fragment removal in all files

(1 post)
  • Started 4 months ago by Rahul

Tags:

  1. Rahul
    guest
    Posted 4 months ago #

    Write a program to remove fragment that occur in all strings,where a fragment
    is 3 or more consecutive word.
    example :
    input::
    s1 = "It is raining and I want to drive home.";
    s2 = "It is raining and I want to go skiing.";
    s3 = "It is hot and I want to go swimming.";
    output::
    s1 = "It is raining drive home.";
    s2 = "It is raining go skiing.";
    s3 = "It is hot go swimming.";
    removed fragment = "and i want to"
    i was told that this program will be tested again large files( in example above string are given as a sample)
    and then we have to remove fragment from files.so efficiency will be taken into consideration.
    Assumptions:Ignore capitalization ,punctuation. but preserve in output.
    I told him that i will map the fragment from first string and then search the others, and we actually need to consider 3 length ones only as a 4 length one will implicitly contain two 3 word phrases and the phrases can overlap.
    i was stuck when he gave me this kind of example
    a a a a a b c b c b c b c
    if we are removing fragment "a b c" ,then after removing middle one we got another "a b c" fragment and so on...


Reply

You must log in to post.

RSS feed for this topic