DEV Community

Arun Kumar
Arun Kumar

Posted on

Interview preparation #1

1 One array

Contains numbers 0 to 9 (random order)
Find two different indices whose values add up to 10
index[]+index[]=10;
Print those indices (value + value= res) ?

let arr = [3, 7, 1, 9, 4, 6, 0, 8, 2, 5];
for (let i=0; i < arr.length; i++) {

for (let j=i+1; j arr.length; j++){

if (arr[i] + arr[j] === 10) {
let res = arr[i]+arr[j];
console.log("value:", arr[i],"+" ,arr[j],"=", res);

}
}
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)