sha1303
BAN USER
Comments (3)
Reputation 10
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
public class ArrayTest {
public static void main(String[] args) {
int target = 12;
int[] intArr = { 1, 3, 5, 7, 7, 8, 8, 9, -2, 14, -5, 0, 4 };
for (int i = 0; i < intArr.length; i++) {
for (int j = i + 1; j < intArr.length; j++) {
if (intArr[i] + intArr[j] == target) {
System.out.println(intArr[i] + ", " + intArr[j]);
}
}
}
}
}
Output =
3, 9
5, 7
5, 7
8, 4
8, 4
-2, 14
Comment hidden because of low score. Click to expand.
0
of 0 vote
This algo won't work for few cases, one such case like -
Store 1 = x1, x2, x3
Store 2 = x1, x2, y3
Store 3 = x3, z1, z2, z3
Customer List = x1, x2, x3, y3, z3
Per above algo, you'll have to go to all 3 stores to get all items in customer list.
But here, Store 2 and Store 3 has all items in the list. No need to go to Store 1 at all.
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Output -
- sha1303 October 11, 201823