chetannihith / Java-hacktoberfest23

Fork this repository to contribute your java programs. If you like this repo give it a star ⭐️.
https://github.com/chetannihith/Java-hack
25 stars 85 forks source link

Chocolate Pickup Solution Added #79

Closed AKASH722 closed 1 year ago

AKASH722 commented 1 year ago

Problem Description:

Ninja has a 'GRID' of size 'R' X Each cell of the grid contains some chocolates. Ninja has two friends Alice and Bob, and he wants to collect as many chocolates as possible with the help of his friends. Initially, Alice is in the top-left position i.e. (O, 0), and Bob is in the top-right place i.e. (0, 'C' - 1) in the grid. Each of them can move from their current cell to the cells just below them. When anyone passes from any cell, he will pick all chocolates in it, and then the number of chocolates in that cell will become zero. If both stay in the same cell, only one of them will pick the chocolates in it. If Alice or Bob is at (i, j) then they can move to (i + 1, j), (i + 1, j - 1) or (i + 1, j + 1). They will always stay inside the 'GRID'. Your task is to find the maximum number of chocolates Ninja can collect with the help of his friends by following the above rules.

Link : https://www.codingninjas.com/studio/problems/ninja-and-his-friends_3125885