Another Problem
Practice
3.8 (4 votes)
Depth first search
Algorithms
Graphs
Problem
71% Success 347 Attempts 30 Points 3s Time Limit 256MB Memory 1024 KB Max Code

While working on his project, Rishi ended up with an interesting problem as follows -

There is a string \(S\) which is broken down into \(N\) chunks (substrings) satisfying the below constraints:

1. For each chunk except the first, starting \(4\) characters will be overlapping with ending \(4\) characters of atleast one chunk.
2. For each chunk except the last, ending \(4\) characters will be overlapping with starting \(4\) characters of atleast one chunk.

Image for the reference:

Your task is to find original message from the given chunks. If multiple solutions exists, then print all of them in lexicographical order.

Note: Number of chunks and overlaps in each test case are generated in a way that it will always pass within given time constriants.

Input Format:

First line contains an integer \(N\) - the number of chunks
The next \(N\) line's contain a string each - representing a chunk

Output Format:

Print all the possible unique original messages in lexicographical order

Constraints:

\(1 \leq N \leq 500 \\ 4 \leq len(chunk) \leq 100 \\\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
10 votes
Tags:
Binary SearchGraphsAlgorithmsDepth First SearchDFS
Points:30
4 votes
Tags:
GraphsAlgorithmsDepth First Search
Points:30
6 votes
Tags:
GraphsAlgorithmsDepth First Search