3242. Design Neighbor Sum Service
You are given a
n x n2D arraygridcontaining distinct elements in the range[0, n2 - 1].Implement the
neighborSumclass:
neighborSum(int [][]grid)initializes the object.int adjacentSum(int value)returns the sum of elements which are adjacent neighbors ofvalue, that is either to the top, left, right, or bottom ofvalueingrid.int diagonalSum(int value)returns the sum of elements which are diagonal neighbors ofvalue, that is either to the top-left, top-right, bottom-left, or bottom-right ofvalueingrid.