Delete fragments in sentence [puzzle]

Question:

Write a program to delete a fragment that occurs in all “lines”, where the fragment is 3 or more consecutive words.

Example:

Input ::

s1 = "It is raining and I want to go home."

s2 = "It is raining and I want to ski."

s3 = "It's hot and I want to swim."

Output::

s1 = "Rain is coming home.";

s2 = "It's raining on skis."

s3 = "Hot swimming."

Remote fragment = "and I want"

The program will again check large files. Efficiency will be taken into account.

Assumptions: Ignore capitalization, punctuation. but saved on exit.

Note: Take care of cases such as

a a a a a b c b c b c b c, .

: ( )

  • int .

    1 2 3 4 5
    3 5 7 9 8
    9 3 1 7 9

.

. (k * nlogn)

k . . else , . . , , .

, ? / ?

+5
3

, izomorphius:

"" (, - - ), .

- . , 3, , , 3 . - ( ).

3- - , 1. 3- x, x -, 1, 2. 3- x, x -, 2, 3. ... . , k, 3-.

3-, .

+1

: "" (, - - ), .

, , . "". , , . , , .

+2

My solution would be something like

F = all fragments with length > 3 shared by the first 2 lines, avoid overlaps
for each line from the 3rd line and up
    remove fragments in F which do not exist in line, or cause overlaps

return sentences with fragments in F removed

I suggest that searching / matching fragments in sentences can be done using some well-known algorithm. but in terms of time complexity for n lines, this is O (n)

0
source

All Articles