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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:49:43+00:00 2026-06-14T01:49:43+00:00

Given an array of integers [a1 a2 … an] , not necessarily distinct, give

  • 0

Given an array of integers [a1 a2 ... an], not necessarily distinct, give an algorithm that returns “yes” if there are distinct indices i,j,k such that ai + aj = ak, and “no” otherwise.

Is there a way to do this faster than brute force, which takes O(n^3)?

  • 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-14T01:49:45+00:00Added an answer on June 14, 2026 at 1:49 am
    • build a list of all possible sums ai + aj: O(n^2).
      The list wil have size=n^2

    • then compare that list with the array, to see whether there are any similarities:

      • first sort each list: O((n^2)log(n^2)) + O(nlogn)
      • walk through them to find any matches: O(n^2)

    total: O((n^2)log(n^2)) ( = O((n^2)log(n)) per comment from alestanis)

    edit: i forgot about the distinct requirement, but that should not change the result.
    first, to assure i!=j, just exclude i==j when building the list of all sums in step 1.
    second, to assure i!=k and j!=k, tag each sum with its indices i,j, and tag each original value with its index k before sorting.
    then in the last step when you find any match, check whether the tagged indices are distinct.

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

Sidebar

Related Questions

Surely there is a framework method that given an array of integers, strings etc
I need a container (like array)for integers in such a way that given x
Given an N-by-N array a of N 2 distinct integers, design an O(N) algorithm
Given an array of integers, how can you find two indices, i and j,
Given an array A of integers, find any 3 of them that sum to
Given an array of N integer such that only one integer is repeated. Find
Suppose that you're given an array A of n distinct elements drawn from some
This problem is taken from interviewstreet.com Given array of integers Y=y1,...,yn, we have n
Given an array of integers A[1...n-1] where N is the length of array A.
Start with an array of integers so that the sum of the values is

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.