Srivathsan
BAN USEROh yeah.. you are right... sorry i cooked a bad soup......:(
- Srivathsan June 09, 2012Vikram, are u sure you've understood the question right ??
- Srivathsan June 09, 2012Simple solution. O(n) complexity.
static void Main(string[] args)
{
int[] ar = { 12, 3, 7, 4 };
int eqIndex = findEquilibriumPoint(ar);
Console.Write(eqIndex);
Console.Read();
}
static int findEquilibriumPoint(int[] arr)
{
int eqIndex = -1;
int ls = arr[0];
int rs = arr[arr.Length - 1];
int s=0, e= arr.Length-1;
while (s < e)
{
if (ls < rs)
{
s++;
ls += arr[s];
}
else if (rs < ls)
{
e--;
rs += arr[e];
}
else
{
if (e - s <= 2)
break;
if ((e - s) > 2)
{
e--;
rs += arr[e];
}
}
}
if (ls == rs)
eqIndex = s+1;
return eqIndex;
}
Foreach element in a do a binary search in b. When you find an element in b replace it with 0 or Int.Minimum value. The binary search should always look in the left half first and then in the right half.
- Srivathsan June 08, 2012Hi Bleep, just out of curiosity, how is the original string reconstructed at the recieving end. can you illustrate the logic with a sentence..? Thanks in advance
- Srivathsan April 08, 2012
RepClariceWright, abc at 8x8
I am a passionate and dedicated travel agent whose mission is to turn travel dreams into reality. I am crazy ...
Hi Sam,
- Srivathsan November 24, 2012Imagine a case where we have multiple numbers occuring odd number of times...XOR will take the solution for a toss.. won't it...??