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

  • SEARCH
  • Home
  • 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 8324555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:06:58+00:00 2026-06-09T00:06:58+00:00

I have a string like 0189, for which I need to generate all subsequences,

  • 0

I have a string like “0189”, for which I need to generate all subsequences, but the ordering of the individual characters must be kept, i.e, here 9 should not come before 0, 1 or 8. Ex: 0, 018, 01, 09, 0189, 18, 19, 019, etc.

Another example is “10292” for which subsequences would be: 1, 10, 02, 02, 09, 29, 92, etc. As you might have noticed ’02’ two times, since ‘2’ comes twice in the given string. But again things like: 21, 01, 91 are invalid as order is to be maintained.

Any algorithm or psuedo code, which could be implemented in C/C++ would be appreciated!

  • 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-06-09T00:07:00+00:00Added an answer on June 9, 2026 at 12:07 am

    I’d recommend using the natural correspondence between the power set of a sequence and the set of binary numbers from 0 to 2^n - 1, where n is the length of the sequence.

    In your case, n is 4, so consider 0 = 0000 .. 15 = 1111; where there is a 1 in the binary expression include the corresponding item from the sequence. To implement this you’ll need bitshift and binary operations:

    for (int i = 0; i < (1 << n); ++i) {
        std::string item;
        for (j = 0; j < n; ++j) {
            if (i & (1 << j)) {
                item += sequence[j];
            }
        }
        result.push_back(item);
    }
    

    Also consider how you’d handle sequences longer than can be covered by an int (hint: consider overflow and arithmetic carry).

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

Sidebar

Related Questions

I have string like Rupeshposts-this-question I need a regular expression which can check whether
I have string like this: G:\Projects\TestApp\TestWeb\Files\Upload\file.jpg How can I remove all text before Files
I have string like {param1=foo}{param2=bar}hello world! I need to extract array of tuples (paramName,
I have string like that: string val = 555*324-000 now, I need to remove
I have string like fullData1 upto fullData10 in this i need to separate out
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have string like this 0 0.014E5 and I need it split into a
Here I have string like this 1322485986.672901000 , data type is string which represents
I have string like [any characters]{$\prime$}[any characters]$[any characters]{$\prime$}[any characters]$[any characters] I want to replace
I have string like this : <input name=my_name id=my_id value=my_value class=my_class /> I would

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.