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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:14:13+00:00 2026-06-15T09:14:13+00:00

I retrieved 200 tweets using jersey API. I want to find two tweets which

  • 0

I retrieved 200 tweets using jersey API. I want to find two tweets which have the longest common substring. This is what I have got. tweetList is an ArrayList of Tweet Objects. comapreTweets method compares tweet objects for longest substring.

Tweet t1=new Tweet();Tweet t2=new Tweet();
    int longestString=0;

    for(int i=0;i<tweetList.size();i++)
    {int store=0;Tweet comparer=null;
        for(int j=i+1;j<tweetList.size();j++)
        {
            if(j!=i){
            int result=tweetList.get(i).compareTweets(tweetList.get(j));
            if(result>store){
                store=result;
                comparer=tweetList.get(j);
            }}
        }
        if(longestString<store)
        {
            longestString=store;
            t1=tweetList.get(i); t2=comparer;
        }
}

If I retrieve 200 tweets then this will loop approx. 40000 times. I require a more efficient way.

EDIT
This loop also compares same tweets in inverted order
Suppose my tweetList contains {a,b,c,d} ; when i=1 and j=3 the comparison is between b & d; when i=3 and j=1 the comparison is d & b. How to avoid this.

SOLUTION instead of j=0 it should be j=i+1. It loops for 19701 times.

  • 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-15T09:14:14+00:00Added an answer on June 15, 2026 at 9:14 am
    199 + 198 + ... + 1 = 19900
    

    I believe 19900 times is a sensible answer. Nearly half of the comparisons in your loops are redundant. You just need to compare the first one to the remaining 199 tweets, the second one to the remaining 198 tweets, and so on. Further optimizaiton better than 19900 times could be possible but I can’t think of one off the top of my head.

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

Sidebar

Related Questions

We have a SQL Server DB with 150-200 stored procs, all of which produce
I have a CustomerID being retrieved and set into a Global Variable. What I
I have never saved and retrieved an image to and from the database before.
I need a variable to hold results retrieved from the database. So far this
I need to put the values retrieved using a Fetch Request from my core
I have a store with items retrieved from server. I would like to detect
I want to display the data retrieved from the JSP page in my List.
You'd think this would be an obvious question that I wouldn't have to ask,
I am using the Advantage Database Server from Sybase and have for the moment
I have a postgresql (v8.4) table with login id and timestamps, and I want

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.