A rock collector is going on a road trip from Southern California to New York. A rectangular grid shows the number of rare rocks available in each city.
Rows and columns are numbered from 0, starting at the top-left. Let rows and cols be the number of rows and columns.
Start at row rows - 1, column 0, and finish at row 0, column cols - 1. Each move goes one row up or one column right. Collect the rocks in every visited city, including the starting and ending cities. Find the maximum total number of rocks you can collect.
int maximumRocks(List<String> cityRocks)
cityRocks: rows from top to bottom. Each string contains the rock counts from left to right, separated by commas, such as "3,0,8".1 ≤ cityRocks.size() ≤ 1,0001 and 1,000 integers, with no spaces. All rows contain the same number of integers.0 and 1,000,000, inclusive.maximumRocks(cityRocks = ["2,1,7", "4,8,0", "3,2,5"])
Output: 23
Move up, right, up, then right to collect 3 + 4 + 8 + 1 + 7 = 23 rocks.
maximumRocks(cityRocks = ["1,2,9", "8,0,7"])
Output: 24
Move right, right, then up to collect 8 + 0 + 7 + 9 = 24 rocks.
maximumRocks(cityRocks = ["6"])
Output: 6
The starting and ending city are the same, so its rocks are counted once.