Posts

2658 - Maximum Number of Fish in a Grid

Image
You are given a  0-indexed  2D matrix  grid  of size  m x n , where  (r, c)  represents: A  land  cell if  grid[r][c] = 0 , or A  water  cell containing  grid[r][c]  fish, if  grid[r][c] > 0 . A fisher can start at any  water  cell  (r, c)  and can do the following operations any number of times: Catch all the fish at cell  (r, c) , or Move to any adjacent  water  cell. Return  the  maximum  number of fish the fisher can catch if he chooses his starting cell optimally, or  0  if no water cell exists. An  adjacent  cell of the cell  (r, c) , is one of the cells  (r, c + 1) ,  (r, c - 1) ,  (r + 1, c)  or  (r - 1, c)  if it exists.   Example 1: Input: grid = [[0,2,1,0],[4,0,0,3],[1,0,0,4],[0,3,2,0]] Output: 7 Explanation: The fisher can start at cell (1,3) and collect 3 fish, then move to cell (2,3) ...

1462. Course Schedule IV

Image
There are a total of  numCourses  courses you have to take, labeled from  0  to  numCourses - 1 . You are given an array  prerequisites  where  prerequisites[i] = [a i , b i ]  indicates that you  must  take course  a i  first if you want to take course  b i . For example, the pair  [0, 1]  indicates that you have to take course  0  before you can take course  1 . Prerequisites can also be  indirect . If course  a  is a prerequisite of course  b , and course  b  is a prerequisite of course  c , then course  a  is a prerequisite of course  c . You are also given an array  queries  where  queries[j] = [u j , v j ] . For the  j th  query, you should answer whether course  u j  is a prerequisite of course  v j  or not. Return  a boolean array  answer , where  answer[j]  is the answer ...