Merging two arrays

Given two sorted integer arrays and the larger array has room for the second. Merge the smaller array into the larger one, in O(n) time and O(1) space.

Answer:

l_begin l_end free
| | |
[4][6][8][10][22][ ][ ][ ][ ]

sml_begin small_end
| |
[1][2][3][20]

void InplaceMerge(int * l_up, int * l_down, int* s_up, int* s_down)
{
int* free = l_down + (s_down-s_up);
while(s_end <= s_begin)
{
while(*l_end >= *s_end)
{
*free = *l_end;
--free; --l_end;
}
while (*s_end >= *l_end)
{
*free = *s_end;
--free; --s_end;
}
}
}

Majority Element of an Array

A majority element in an array A, of size N is an element that appears more than N/2 times (and hence there is atmost one such element)

Write a function which takes an array and emits the majority element (if it exists), otherwise prints NONE as follows:

I/P : 3 3 4 2 4 4 2 4 4
O/P : 4

I/P : 3 3 4 2 4 4 2 4
O/P : NONE

Duplicates in an array

Given an array of length N containing integers between 1 and N, determine if it contains any duplicates.