Anonymous0708
BAN USERSoftware engineer
Hi Solution for this problem is :
Elements of a category are : n
Elements of b category are : n
array size is 2n
1) Go to n+1 postion.
2) Pick this element is toggle it with element at nth position.
3) Now go to nth position and toggle it with element at n-1 position.
4) REPEAT step 2-3 n-1 times.
5) Once done now go to n+2 and repeat steps 2-5 n-2th times.
6) Final array will be a1, b1, a2, b2, a3, b3,...
Code................
int[] a = new int[10] { 1, 3, 5, 7, 9, 2, 4, 6, 8, 10 };
int nth = 5;
for (int Z = 0; Z <= nth - 2; Z++)
{
for (int j = 0; j < nth - 1 - Z; j++)
{
int temp;
temp = a[nth - j + Z];
a[nth - j + Z] = a[nth - 1 - j + Z];
a[nth - 1 - j + Z] = temp;
}
}
// sorted array a here .
In my view we need not sort the array.
- Anonymous0708 November 21, 20071. Start from first element and find its duplicate against rest of elements ahead of it in array.
2. If found continue else break.
3. Keep moving ahead unless you find the number.