Question: Answer the following question using Java (1) Given an array of integers, find two numbers such that they add up to a specific target number.

Answer the following question using Java

Answer the following question using Java (1) Given an array of integers,

(1) Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. You may assume that each input would have exactly one solution. nput: Take two integers as input. N and T, where N is the number of elements in the array and T is the target number. Next, take N integers as input and store them in the array. Output: The output should contain the two indices, index1 and index2 in the following format: [index1, index2] If there is no pair that sum to T, output [-1,-1] Expected Time Complexity: O(n) Sample Input 2 7 11 15 Sample Output [0, 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!