Yahoo Interview Question
Software Engineer / Developerscalcprobablity(int i,int j){
int tot=totalconfinside(i,j)
prob=tot/8(calcprobablity(i-1,j+2)+calcprobablity(i-1,j-2).....)
return prob
}
int totalconfinside(i,j){
int cnt=0;
if(valid(i-1,j+2))
cnt++
if(valid(i-1,j-2))
cnt++
return cnt
}
isvalid(int i,int j){
if(i>0 && i <8 && j>0 && j<8)
return true
else
return false
}
Brute Force Back-Tracking i guess. Need to create a search Tree/Decision Treee. Start with a node. make all 8 movements. Chk if new coordinate lies within chess board, if no increment the counter variable 'failed' by 1 and else increment counter variable success by 1. Ignore the rest of the tree where nodes/vertices were failed. Traverse till nth level of decision tree. success/(success+failed) must be the probability.
- PrateekCaire September 14, 2010