satishkv.pesit
BAN USERimport java.util.Arrays;
public class FindSubArray {
public static int[] arr = { -1, -5, 2, 3, 1, 2, 3, 4, 6, 7, 7, 4, 5, 6, 3, 6, 8, 9, 12, 15, 12, 14, 1 };
public static void main(String[] args) {
Arrays.sort(arr);
int target = 12;
findAllElementsSumingToTarget(arr, target);
}
public static void findAllElementsSumingToTarget(int[] arr, int target) {
int sum = 0;
for (int i = 0; i < arr.length; i++) {
int count = 1; // This variable takes care of summing sub arrays in while loop
while (count < arr.length) {
for (int j = i + 1; j < arr.length; j++) { //This J loop is to iterate through each element (i+1)
sum = arr[i] + sumSubArray(j, count); // sumSubArray will add elements starting from i+1 to arr.length
if (sum == target && arr[i] != target) {
matchedArray(i, j, count);
}
}
count++;
}
count = 1;
}
}
public static int sumSubArray(int start, int elements) {
int sum = 0;
for (int i = start; i <= elements; i++)
sum += arr[i];
return sum;
}
public static void matchedArray(int start, int subArrayStart,
int lengthOfSubArray) {
if (lengthOfSubArray > 1) {
System.out.print("\nFound Array : " + arr[start] + " ,");
for (int i = subArrayStart; i <= lengthOfSubArray; i++)
System.out.print(arr[i] + " ,");
System.out.println();
}
}
}
Meeting rooms are stored in an arrayList and each node will have 1440 integer arrays which will be filled when someone tries to book a meeting room.
- satishkv.pesit October 02, 2016