Given 3 sorted array. Find 3 elements, one from each array such that a+b=c. Can it be done less than O(n^3) time complexity? Please help me.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
It can be done in O(N^2 * logN) complexity by iterating through 2 of the arrays for a and b and binary searching for c in the third array.
Another method would be O(N^2) by inserting the elements of one of the arrays into a hash, iterate for a and b in the other two arrays and looking if c = (a + b) exists in the hash.