I believe this (recursive) solution is correct for the Champagne Tower Problem, however, the timeout constraint avoids to run all the tests. Is there any way to run all the tests without such a constraint?
class Solution {
public double champagneTower(int poured, int query_row, int query_glass) {
return Math.min(1, input(poured, query_row+1, query_glass+1));
}
private double input(int p, int r, int c) {
if(r*c==1) return p;
if(c<=0 || c>r) return 0;
double izq = Math.max(0, (input(p, r-1, c-1)-1)/2);
double der = Math.max(0, (input(p, r-1, c)-1)/2);
return (izq + der);
}
}