Computer Science, asked by subhadip876, 4 months ago

The function/method manchester print space-separated integers with the following property for each
element in the input array arr, a counter is incremented if the bit arri] is the same as arrfi-1]. Then the
increment counter value is added to the output array to store the result.
If the bit arr[i] and arr[i-1] are different, then 0 is added to the output array. For the first bit in the input array
assume its previous bit to be 0. For example, if arr is {0,1,0,0,1,1,1,0), the function/method should print 100
20340.​

Answers

Answered by jokerthegamer15
5

Input: arr[] = {3, 2, 0, 1}

Output: arr[] = {1, 0, 3, 2}

Explanation:

In the given array

arr[arr[0]] is 1 so arr[0] in output array is 1

arr[arr[1]] is 0 so arr[1] in output array is 0

arr[arr[2]] is 3 so arr[2] in output array is 3

arr[arr[3]] is 2 so arr[3] in output array is 2

Input: arr[] = {4, 0, 2, 1, 3}

Output: arr[] = {3, 4, 2, 0, 1}

Explanation:

arr[arr[0]] is 3 so arr[0] in output array is 3

arr[arr[1]] is 4 so arr[1] in output array is 4

arr[arr[2]] is 2 so arr[2] in output array is 2

arr[arr[3]] is 0 so arr[3] in output array is 0

arr[arr[4]] is 1 so arr[4] in output array is 1

Input: arr[] = {0, 1, 2, 3}

Output: arr[] = {0, 1, 2, 3}

Explanation:

arr[arr[0]] is 0 so arr[0] in output array is 0

arr[arr[1]] is 1 so arr[1] in output array is 1

arr[arr[2]] is 2 so arr[2] in output array is 2

arr[arr[3]] is 3 so arr[3] in output array is 3

Similar questions