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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:00:39+00:00 2026-06-14T14:00:39+00:00

I have an arraylist of different phrases such as, protein, protein kinase, functional, functional

  • 0

I have an arraylist of different phrases such as, “protein”, ” protein kinase”, “functional”, “functional protein”, “sox5”, “il-6”, Now, if I give a sentence as input, “functional protein kinase and il-6 and sox5”, it must provide output as, “{functional protein} kinase and {il-6} and {sox5}”. Every word in the sentence must be compared with the phrases.

The code that I have done returns me starting and ending indexes of different strings which are compared with the arraylist of different phrases. I need to filter out only the indexes which is largest and without any collisions.
For e.g.
Input:

[0, 7][8, 22][8, 15] [36, 43] [23, 43] [20, 30]

Required output:

[0, 7] [8, 22] [23, 43]

Cases:

  • Between [8, 22] and [8, 15], [8, 22] is the largest because 22-8 = 14 > 15-8 = 7, so [8,22] must be selected.
  • Between [36, 43], [23, 43] and [20, 30], 36 lies in the range [23, 43] and 30 also lies in the range [23, 43] which is collision but among these collisions, [23, 43] is
    largest and must be selected.

What should I do in order to get the required output? (comparing criteria)

I have done,

ArrayList<ArrayList<Integer>> ListOfList = new ArrayList<ArrayList<Integer>>();
for(int a = 0; a<ListOfList.size();a++)
        {
            if(a == ListOfList.size()-1) break;
            for(int b = a+1; b<ListOfList.size();b++)
            {
                if((ListOfList.get(a).get(0) == ListOfList.get(b).get(0)) && (ListOfList.get(a).get(1) < ListOfList.get(b).get(1)))     
                {
                    startOffset = ListOfList.get(b).get(0);
                    endOffset =  ListOfList.get(b).get(1);
                }
                else
                {
                    startOffset = ListOfList.get(a).get(0);
                    endOffset =  ListOfList.get(a).get(1);
                }
            } 
        }
  • 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-14T14:00:40+00:00Added an answer on June 14, 2026 at 2:00 pm

    From what I understand your solution would be to group all pairs with intersecting indexes, and then just find the one with max length in each group. Here’s some boilerplate code. Let me know if you need more clarification:

    static class Pair {
    public int start, end;

        Pair(int start, int end) {
            this.start = start;
            this.end = end;
        }
    
        public int weight() {
            return end - start;
        }
    
        public boolean contains(int point) {
            return start <= point && point <= end;
        }
    
        public String toString() {
            return String.format("[%d, %d]", start, end);
        }
    }
    
    static class Group {
        public List<Pair> pairs = new ArrayList<Pair>();
        public Pair maxWeight;
    
        Group(Pair start) {
            add(start);
        }
    
        Group(List<Pair> pairs) {
            for (Pair pair : pairs) {
                add(pair);
            }
        }
    
        public boolean contains(Pair pair) {
            for (Pair my : pairs) {
                if (my.contains(pair.start) || my.contains(pair.end))
                    return true;
            }
            return false;
        }
    
        public void add(Pair pair) {
            pairs.add(pair);
            if (maxWeight == null || maxWeight.weight() < pair.weight())
                maxWeight = pair;
        }
    }
    
    public static void main(String[] args) {
        List<Pair> pairs = new ArrayList<Pair>();
        pairs.add(new Pair(0, 7));
        pairs.add(new Pair(8, 15));
        pairs.add(new Pair(8, 22));
        pairs.add(new Pair(36, 43));
        pairs.add(new Pair(23, 43));
        pairs.add(new Pair(20, 30));
        List<Group> groups = new ArrayList<Group>();
    
        for (Pair pair : pairs) {
            List<Group> intersects = new ArrayList<Group>();
            for (Group group : groups) {
                if (group.contains(pair)) {
                    intersects.add(group);
                }
            }
    
            if (intersects.isEmpty()) {
                groups.add(new Group(pair));
            } else {
                List<Pair> intervals = new ArrayList<Pair>();
                intervals.add(pair);
                for (Group intersect : intersects) {
                    intervals.addAll(intersect.pairs);
                }
    
                groups.removeAll(intersects);
                groups.add(new Group(intervals));
            }
        }
    
        for (Group group : groups) {
            System.out.println(group.maxWeight);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an arraylist that gets different type of values in it, 1st value->
I have an ArrayList of Routine objects and I must use this method to
I have 9 different ArrayList and I want to have a list of the
I have some arraylist with different objects of the same interface type, e.g: Interface
I have an arrayList of different types of players based on sports. I need
I have an arrayList with a number of different objects including Log , Frog
I have a ArrayList made up of different elements imported from a db, made
I have an ArrayList of objects that I need to sort in two different
I have a different arraylist with column names. I want to have a generatized
i have a problem of passing two values in different ArrayList s. I made

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.