shukad333
BAN USER 1of 1 vote
AnswerYou and your friends are pilots in the Clone army.You are facing the aerial fleet of the Droid army.Droid planes move while maintaining a long line so that their shields interact making it impossible to shoot down planes in the middle of the line.Thus,your only option is to keep shooting down planes at the edges of the line.
 shukad333 in United States
You and your friend have decided to make a game of it.Each Droid plane has an importance level IMP[i].Since the droid planes don't advertise their importance levels, both of you must follow a mixed strategy and shoot down either the first plane or the last plane with 50% chance each.If there is a single plane,the shooter with the turn will shoot it down for sure.The two of you take turns to shoot down enemy planes.You have the first turn.What is the expected sum of importance levels you will shoot down?
Input format:
# The number of droid planes
input1=N(1<=N<=1000)
# An array containing the importance levels of droid planes.
input2=IMP(for 0<i<=N,1<=IMP[i]<=100)
Output format:
A string containing your expected sum of importance levels of shot down planes,rounded to 3 places of decimal.
Example:
Input:
2
10 20
Output:
15.000 Report Duplicate  Flag  PURGE
Capgemini
static int findRotatedArrayIndex(int n , int[] arr) {
int st = 0;
int end = arr.length;
while(st <= end) {
int mid = (st + end)/2;
if(n == arr[mid])
return mid;
if(arr[mid] > arr[st]) {
if(n < arr[mid] && arr[st] < n) {
end = mid  1;
}
else
st = mid + 1;
}
else {
if(arr[mid]<n && arr[end] > n) {
st = mid + 1;
}
else
end = mid 1;
}
}
return 1;
}

shukad333
August 28, 2014
Although time contraint is more , this will do the job...
O/p : 7
 shukad333 August 28, 2014