Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6808891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:00:43+00:00 2026-05-26T20:00:43+00:00

Lets say you have a string: abcde And a set of strings: ab, cde,

  • 0

Lets say you have a string: abcde

And a set of strings: ab, cde, abcd, a, bcd, cd

You want to find all possible concatenations from the set that form the string.

You can use recursion to traverse through all possible concatenations from the set, but how would you return only those that satisfy the solution?

The possible combinations:

ab - cde - yes
ab - cd - no
abcd - no
a - bcd - no
ab - cd - no

You can build a tree from the traverse and then extract the paths that complete. Is there a way without using a tree?

I am implementing this in Python but feel free to answer in any language.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:00:43+00:00Added an answer on May 26, 2026 at 8:00 pm

    One possibility is to structure the search as a generator. In python, it might look like this:

    def concatenations(target_string, fragments, concat_path=()):
        if not target_string:
            yield concat_path
        else:
            for frag in fragments:
                if target_string.startswith(frag):
                    new_target = target_string[len(frag):]
                    new_path = concat_path + (frag,)
                    for c in concatenations(new_target, fragments, new_path):
                        yield c
    

    Note that I have assumed that the elements from the set can occur more than once in the string. If that is inappropriate, replace fragments by fragments - {frag} in the recursive call.

    You can get all elements by just gathering all the results from the generator into a list:

    fragments = {"ab", "cde", "abcd", "a", "bcd", "cd", "e"}
    list(concatenations("abcde", fragments))
    

    This produces:

    [('a', 'bcd', 'e'), ('abcd', 'e'), ('ab', 'cde'), ('ab', 'cd', 'e')]
    

    You could also accumulate all the results into a list as the search proceeds.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say, we have string ABCAD, now we need to iterate through all possible
lets say I have a string that I want to split based on several
Lets say that I have 10,000 regexes and one string and I want to
Possible Duplicate: Evaluate C# string with math operators So lets say I have a
lets say i have a number string 1234567890 and out of that i want
I have two string that i want to limit to lets say the first
Lets say I have two strings: string s1 = hello; string s2 = hello
Lets say I have a string COLIN. The numeric value of this string would
Lets say a have a string such as this one: string txt = Lore
Lets say I have the string: MyNamespace.SubNameSpace.MyClassName How do I extract just everything after

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.