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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:43:54+00:00 2026-06-02T16:43:54+00:00

I have been given this below problem in school, I have solved as per

  • 0

I have been given this below problem in school, I have solved as per my understanding and solution is as below. Can someone please help me to give a better solution for the same.

Question:

Produce a software application that creates a filtered merging of two case-insensitive sorted lists. The first input list is designated as the Source list and the other as the Prefixes list. The application will produce a merged list containing items that come from the Source and Prefixes lists using the following algorithm:

An item X is in the merged list if and only if one of the following is true:

a) X is from the Source list and there is an item Y in the Prefixes list that is a case-insensitive string prefix for X.

b) X is from the Prefixes list and there is no item in the Source list for which X is a case-insensitive string prefix.

The completed merged list should be in the same sort order as the items in the original two lists.

My Solution:

public ArrayList<String> merge(List<String> srcList, List<String> preList) {
        // If Prefixes list is empty then there cannot be a new merge list
        if (preList.isEmpty()) {
            return null;
        }
        int i = 0, j = 0;
        int sourcesListSize = srcList.size();
        int prefixesListSize = preList.size();
        ArrayList<String> mergeList = new ArrayList<String>();
        // Loop through Sources list until end of the list is reached
        //ASSUMPTION: Both SourceList and PrefixList are already sorted.
        while (i < sourcesListSize && j<prefixesListSize) {
            mergeList.add(preList.get(j).concat(srcList.get(i)));
            i++;
            j++;
        }
        // If Prefixes list still have items, then add it to mergeList
        while (j < prefixesListSize) {
            mergeList.add(preList.get(j));
            j++;
        }
        return mergeList;

    }

Input:

  • Source list: {"pple","ow","enver",pic,"ull"}
  • PrefixList: {"a","c","d","e","f"}

MergeList={"apple",cow","denver","epic","full"}

Is my understanding correct? Is there any best other solution?

  • 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-02T16:43:56+00:00Added an answer on June 2, 2026 at 4:43 pm

    Since this is homework I’ll try not to give too much away, but per the definition of prefix, here are some examples:

    “a” is a prefix of “Apple”

    “cow” is a prefix of “Cow”

    “g” is not a prefix of “Zoo”

    “col” is not a prefix of “cool”

    Based on that, what will the MergeList be for the following? Hint: there will be items from both SourceList and PrefixList in the correct MergeList. Post your solution and I’ll critique it. Once you understand how this part works, you’ll have a much better idea of how to code the solution.

    SourceList : {“Apple”,”Pepper”,”Denver”, “Garage”, “Zoo”}

    PrefixList : {“a”,”d”,”pe”,”xylophone”,”e”}

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

Sidebar

Related Questions

I have been working on this problem for quite some time and can't figure
Given that I have this resultset structure (superfluous fields have been stripped) Id |
I have been given the following request. Please give 7% of the current contacts
I have been given an app written by someone else and the error I
I've been thinking of this problem, and I have not found a good, efficient
I've been working on this application but have come across a problem that I
I have this problem. Given a users table that consists of users' username in
I have been given a w2k3 server today that is running IIS 6. This
I have given below simplified JavaScript problem. var PROJ=(function(){ var tags={}, var lock=true; function
Okay. Now I give up. I have been playing with this for hours. I

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.