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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:35:39+00:00 2026-06-06T12:35:39+00:00

Given the following problem , I’d appreciate for any corrections since I have no

  • 0

Given the following problem , I’d appreciate for any corrections since I have no solution
for the current question (taken from one of my professor’s exams !!!) :

Remark: this is no homework !

Problem:

Given two sorted arrays A (with length n) & B (with length m) , where each

element (in both arrays) is a real number , and a number X (also a real number) ,

we’d like to know whether or not exists a ∈ A and b ∈ B , such as :

a + b = X , in O(n+m) running time .

Solution :

First , we start to check from the end of both arrays , since we don’t need the numbers that are bigger than X :

  • i = n
  • k = m

  • while A[i] > X , i = i -1

  • while B[k] > X , k = k -1

Define j = 0 .
Now start running from the current i in A , and from j in B :

  • while i > 0 , j < k :
  • if A[i]+B[j] == X , then return both cells
  • else j = j+1 , i = i -1

In the end we’d have either the two elements , or we’d reach out of bounds in one
or both of the arrays , which means that no two elements such a + b = X are indeed exist .

Any remarks would be much appreciated

Thanks

  • 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-06T12:35:41+00:00Added an answer on June 6, 2026 at 12:35 pm

    You shouldn’t adjust i and j at the same time. If the sum is too big, you should decrease i. If it is too small, increase j.

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

Sidebar

Related Questions

The following problem is taken from Problems on Algorithms (Problem 653): You are given
I have the following problem, given the following service contract, data contract, and service
I have the following problem: I am given a tree with N apples, for
Problem One friend suggested an interesting problem. Given the following code: public class OuterClass
I have a problem with nested templates and their template specialization. Given the following
I have the following problem: Given N objects (N < 30) of different values
Consider the following problem. We are given an array of elements belonging to one
Hi I have the following problem. Given a Tree I want to be able
In Programming Pearls I have met the following problem. The question is this: print
Please help me to resolve the following problem: First of all, I have one

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.