Home /
Expert Answers /
Computer Science /
solve-this-question-with-the-complexity-of-o-n-given-two-integer-array-nums-of-distinct-i-pa615
(Solved):
Solve this question with the complexity of \( O\{n\} \) Given Two integer array nums of distinct i ...
Solve this question with the complexity of \( O\{n\} \) Given Two integer array nums of distinct items and a target value. Return the index for both arrays when the difference between elements is equal to the target value if there is no item in both array whose difference is equal to the target then return \( [-1,-1] \) Example 1: Input: numsFirst \( =[3,4,10] \) Input: numsSecond \( =[1,4,8] \) Input: target \( =5 \) Output: nums \( =[0,2] \) eg: 8 from numsSecond - 3 from numFirst is equal to 5 which is target Example 2: Input: numsFirst \( =[2,4,10] \) Input: numsSecond \( =[1,4,8] \) Input: target \( =5 \) Output: nums \( =[-1,-1] \)
Here is your Java solution in O(n) time complexity , Check it out! Code import java.util.*; public class Main { public static void main(String[] args) { int []arr1 = {2,4,10}; int []arr2 = {1,4,8}; int tar