Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6564 |

@blackshadows | 6400 |

@mb1973 | 5785 |

@Quandray | 5275 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 5074 |

@kirtidee18 | 4639 |

@sanjay05 | 3762 |

@mantu_singh | 3712 |

@gfgaccount | 3627 |

@marius_valentin_dragoi | 3525 |

Complete Leaderboard | |

Handle | Score |

@yaswanthero123 | 625 |

@vikash619 | 611 |

@venkat11803610 | 501 |

@roshan13ar | 396 |

@DevangSingh | 379 |

@ravi11815721 | 312 |

@hrishipangavhane | 286 |

@aryanjain85297 | 280 |

@kommaraju11806903 | 277 |

@infosumitraut | 272 |

@ankitsharma5422 | 256 |

Complete Leaderboard |

There is a stack of water glasses in a form of pascal triangle and a person wants to pour the water at the topmost glass, but the capacity of each glass is 1 unit. Overflow takes place in such a way that after 1 unit, 1/2 of remaining unit gets into bottom left glass and other half in bottom right glass.Now John pours **K** units of water in the topmost glass and wants to know how much water is there in the **C**th glass of the **R**th row.

**Note:** Assume that there are enough glasses in the triangle till no glass overflows.

**Example 1:**

Input:K =3,R =2,C =1Output:1.000000Explanation:After the first glass, 2 units of water will remain and they will spread equally on the two glasses on the second row. Therefore, the glass on the 2nd row and 1st column will have 1 unit of water.

**Example 2:**

Input:K =3,R =2,C =2Output:1.000000Explanation:After the first glass, 2 units of water will remain and they will spread equally on the two glasses on the second row. Therefore, the glass on the 2nd row and 2nd column will have 1 unit of water.

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function **waterOverflow()** which takes 3 Integers K, R and C as input and returns the amount of water in the Cth glass of Rth row.

**Expected Time Complexity:** O(K^{2})

**Expected Auxiliary Space:** O(K^{2})

**Constraints:**

1 <= K <= 500

1 <= R,C <= K

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Water Overflow

...