Since both arrays are already sorted, that means that the first int of one of the arrays will be smaller than all the ints that come after it in the same array. We also know that if the first int of arr1 is smaller than the first int of arr2, then by the same logic, the first int of arr1 is smaller than all the ints in arr2 since arr2 is also sorted.
public static int[] merge(int[] arr1, int[] arr2) {
int i = 0; //current index of arr1
int j = 0; //current index of arr2
int[] result = new int[arr1.length+arr2.length]
while(i < arr1.length && j < arr2.length) {
result[i+j] = Math.min(arr1[i], arr2[j]);
if(arr1[i] < arr2[j]) {
i++;
} else {
j++;
}
}
boolean isArr1 = i+1 < arr1.length;
for(int index = isArr1 ? i : j; index < isArr1 ? arr1.length : arr2.length; index++) {
result[i+j+index] = isArr1 ? arr1[index] : arr2[index]
}
return result;
}
So this implementation is kind of confusing, but it's the first way I thought to do it so I ran with it. There is probably an easier way, but that's the beauty of programming.
A quick explanation:
We first loop through the arrays comparing the first elements of each array, adding whichever is the smallest to the result array. Each time we do so, we increment the index value (i or j) for the array that had the smaller number. Now the next time we are comparing the NEXT element in that array to the PREVIOUS element of the other array. We do this until we reach the end of either arr1 or arr2 so that we don't get an out of bounds exception.
The second step in our method is to tack on the remaining integers to the resulting array. We need to do this because when we reach the end of one array, there will still be at least one more integer in the other array. The boolean isArr1 is telling us whether arr1 is the array with leftovers. If so, we loop through the remaining indices of arr1 and add them to the result. Otherwise, we do the same for arr2. All of this is done using ternary operations to determine which array to use, but if we wanted to we could split the code into two for loops using an if statement.
Answer:
True.
Explanation:
When you established social links, your social media site profile may eliminate almost any generic symbol throughout the list of contacts and the Individuals Pane with profile pic the contact may have placed. Thus, the Users Pane would be exchanged with profile image of the contact while establishing the social connections.
Answer: your books and the ones you are given access to.
Explanation: quickbooks goes from day to day bookkeeping to month and year end financial reports and tax filing. businesses use to manage daily sales and expenses and also keep track of daily transactions. They can involve or outsource bookkeepers or choose to run in-house operations. In doing this they would have access to all their books or decide to give virtual access to their outsourced bookkeeper/accountant. Quickbooks has multiple features concerning user access and privacy. A quick books user, in this case the business, can restrict access for each user it decides to add. The user can decide to give free access to all books or decide to restrict to a few files. Example, the business may add an accountant as one of its users and decide to restrict the accountant to its payroll files, depending on the agreement.
The best and most correct answer among the choices provided by the question is the second choice. <span>Siltstone is made mostly of silt. </span>I hope my answer has come to your help. God bless and have a nice day ahead!
Answer:
A
Explanation:
var3 is happy + birthday, ×2
l.e happy birthday happy birthday