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 1103983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:25:14+00:00 2026-05-17T01:25:14+00:00

Example : S1 : abcde S2: cdef Answer : cde

  • 0

Example :

S1 : abcde
S2: cdef

Answer : cde

  • 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-17T01:25:15+00:00Added an answer on May 17, 2026 at 1:25 am

    It’s reasonable to assume the set of characters is small and finite compared to the potential string length. So, handling 8-bit characters for example (in roughly-C++ pseudo-code):

    bool in_a[256] = { false };
    bool in_b[256] = { false };
    for (int i = 0; i < a.size(); ++i)
        in_a[a[i]] = true;
    for (int i = 0; i < b.size(); ++i)
        in_b[b[i]] = true;
    // and in_a and in_b
    for (int i = 0; i < b.size(); ++i)
        if (in_a[i] && in_b[i])
        {
            std::cout << i;
            if (isprint(i)) std::cout << '\'' << (char)i << '\'';
            std::cout << ' ';
        }
    std::cout << '\n';
    

    Note that using a hash table rather than an array is a huge waste of time (unless handling say a 32-bit character representation).

    An implementation of the simplification suggested in Yordan’s comment follows. This avoids the final loop from 0..255 and needs only one tracking array. The order of results is unsorted.

    #include <vector>
    #include <iostream>
    
    int main()
    {
        std::string a = "abdcdefg";
        std::string b = "byfdz";
        bool track[256] = { false };
        for (int i = 0; i < a.size(); ++i)
            track[a[i]] = true;
        for (int i = 0; i < b.size(); ++i)
            if (track[b[i]])
            {
                track[b[i]] = false; // don't match again
                std::cout << (int)b[i];
                if (isprint(b[i])) std::cout << " \'" << (char)(b[i]) << "\'";
                std::cout << ' ';
            }
        std::cout << '\n';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do retrieve the first word of a string in C++? For example, abcde
In PHP manual given example is echo substr_compare(abcde, bcg, 1, 2); // 0 I
For example, this regex (.*)<FooBar> will match: abcde<FooBar> But how do I get it
Given an array with n values, for example: $arr[] = 'ABCDEFABC'; $arr[] = 'ABCDEFDEF';
Given any iterable, for example: ABCDEF Treating it almost like a numeral system as
Example Div: <div class=container> <div class=select1></div> <div class=select2></div> <div class=select3></div> </div> Now I want
Example: print max(chain_length(i) for i in xrange(1,10001)) This returns the maximum/biggest chain_length (an arbitrary
Example: $ objdump Logger.cpp.o -t 00000000 g F .text 00000000 .hidden __sti___10_Logger_cpp_0b2ae32b
Example: copy in one tmux pane (via vim), then switch to another pane (running
Example: an Employee table with an optional DateOfBirth field can be normalized into two

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.