Create ever smaller arrays of items and then merge them to


Merge - Arrays

In a merge sort, you create ever smaller arrays of items and then merge them to create a final, fully sorted array. In this challenge, you will have two sorted arrays that must be merged to form a single, sorted array. Each of the arrays will be sorted in non-decreasing order.

As an example, consider the arrays a = [1, 2, 3] and b = [2, 5, 5]. Merge the arrays to create array c as follows:

a[0] < b[0] → c = [a[0]] = [1]
a[1] = b[0] → c = a[0], b[0]] = [1, 2]
a[1] < b[1] → c = [a[0], b[0], a[1] = [1, 2, 2]
a[2] < b[i] → c = [a[0], b[0], a[1], a[2] = [1, 2, 2, 3]
No more elements in a → c = a[0], b[0], a[1], a[2], b[1], b[2] = [1, 2, 2, 3, 5, 5]

Elements were alternately taken from the arrays in the order given, maintaining precedence.

Function Description

Complete the function mergeArrays in the editor below. The function must return an array of all the elements from both input arrays in non-decreasing order.

mergeArrays has the following parameter(s):

a[a[0],...a[n-1]]: a sorted array of integers

b[b[0],...b[n-1]]: a sorted array of integers

Lonely Integer

Consider an array of n integers, arr = [a0, a1, ...an-1, where all but one of the integers occur in pairs. In other words, every element in arr occurs exactly twice except for one unique element.

Complete the lonelyinteger function in the editor below. It has one parameter: an array of integers, arr. The function must find and return an integer denoting the unique element in array arr.

Input Format
Locked stub code in the editor reads the following input from stdin and passes it to the function:

The first Line contains an integer, n, denoting the number of elements in arr.

Each line i of the n subsequent lines (where 0 ≤ i ≤ n) contains an integer describing element 0

Constraints
• 1 ≤ 100
• n is odd.
• 0 ≤ a1 ≤ 100, where 0 ≤ i < n

Output Format

The function must return an integer denoting the unique element in the array. This is printed to stdout by locked stub code in the editor.

Sherlock and The Beast

Sherlock Holmes and his dear friend Dr. Watson are working on an urgent problem. Watson had earlier learned through his ''special relationship'' contacts at MI6 that that the CIA has lately been facing weird problems with their supercomputer, The Beast'. Then, Sherlock received a note from Professor Moriarty, his archenemy, boasting that he has infected 'The Beast' with a virus.

Now, all of Sherlock's past efforts to subdue Moriarty had been in vain, but the note gave him new hope to finally triumph over his nemesis. You see, the note had been written on a piece of paper previously sat on Moriaty's desk under another piece of paper. Unbeknownst to anyone but the intrepid Sherlock Holmes, it had an impression of a number N on it. After following up with more clues from his past experience with Moriarty, Sherlock figured out that the key to remove the virus is the largest 'Decent' Number having N digits.

A 'Decent' Number has -
1. Only 3 and 5 as its digits.
2. The number of times 3 appears is divisible by 5.
3. The number of times 5 appears is divisible by 3.

Meanwhile, the trigger date of the virus to completely wipe the disk and burn out the processors of The Beast' is fast approaching. Can you save The Beast', and find the key for Sherlock?

Input Format
The first line will contain an integer T, the number of test cases. This is followed by T lines, each containing an integer N i.e the number of digits in the number

Attachment:- Testcases.zip

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: Create ever smaller arrays of items and then merge them to
Reference No:- TGS02732048

Now Priced at $35 (50% Discount)

Recommended (96%)

Rated (4.8/5)