Abhishek
BAN USERlets name couples as H1,W1,H2,W2,H3,W3,H4,W4
initially all are in side 1
1.H1 and W1 will cross the river.W1 will stay in side 2 and H1 will come back.
2.H2 and W2 will cross the river.W2 will stay in side 2 and H2 will come back.
3.H1 and H2 will cross the river.H1 will stay in side 2 and H2 & W2 will come back.
4.W2 and W3 will cross the river.Both W2 and W3 will stay in side 2 and H1 will come back.
5.H1 and H2 will cross the river.Both H1 and H2 will stay in side 2 and W3 will come back.
6.H3 and W3 will cross the river.Both H3 and W3 will stay in side 2 and W1 & W2 will come back.
7.H4 and W4 will cross the river.Both H4 and W4 will stay in side 2 and W3 will come back.
8.W1 and W2 will cross the river.W1 will stay in side 2 and W2 will come back.
9.Finally both W2 and W3 will cross the river.
Let the first element be required element(say result).Take a variable count initially initialized to 1.now start scanning the array from 2nd element.if element is same as result then increase the count else decrease the count.When count reaches to 0,make result as current element and initialize count to 1.At the end,result will contain the required element.
- Abhishek September 20, 2012