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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:13:14+00:00 2026-05-26T14:13:14+00:00

This is not an original problem. I had a complex problem which is now

  • 0

This is not an original problem. I had a complex problem which is now reduced to the following:

There are two sorted arrays, A and B with m and n elements respectively, m = \Theta(n)
Can an algorithm that runs in o(mn) time find the maximum number of pairs such that A[i]-B[j] <= T where T is some constant? How can this be done?

edit:

  1. The pairs should be disjoint, i.e. one element can be selected at most once.

  2. The algorithm should run in little-o(mn) meaning that a solution that runs in mn time is not acceptable.

  3. Is it also possible to find the pairs that we select?

Clarification:

If the arrays are a_1, a_2, ..., a_m and b_1, b_2, ..., b_n, I need to find pairs (a_i, b_j) such that |a_i - b_j| <= T. It is not allowed to choose an element more than once. How can we maximize the number of pairs given the arrays?

  • 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-26T14:13:14+00:00Added an answer on May 26, 2026 at 2:13 pm

    UPDATE 2:

    The updated question (only use an element from either array once, get the pairs, and the absolute difference of the values must be below T) might be able to be done in O(n+m) time. I haven’t thought through the algorithm below enough to decide if it will always get the maximum number of pairs or not, but it should in most cases:

    int i = 0;
    int j = 0; 
    
    while(i < A.length){
        while(j < B.length){
            if(A[i]-B[j] <= T){
                if(A[i]-B[j] >= -1 * T){
                    addPair(i, j);
                    j++;//don't consider this value the next time
                }
                break;
            } 
            j++;
        }
        i++;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is not academic code or a hypothetical quesiton. The original problem was converting
I managed my original problem i had to add the break; but now the
Had a problem in a complex linq query so I simplified it in LINQPad:
I am reposting this question due to inability to solve the problem (original here
Original question is below. I fixed my problem. I had the same view controller
This is a follow up on another problem i had with getting-the-last-record-inserted-into-a-select-query I am
I have the following problem with Qt (no answer on this site seemed to
Solved This is now solved: In the tmbLoaded function all I had to do
Sorry for this not being a real question, but Sometime back i remember seeing
I ask this not to start anything negative. Rather, after looking at ASP.NET MVC

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.