MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / SubrectangleQueries

Class SubrectangleQueries

SubrectangleQueries.java:1–25  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class SubrectangleQueries {
2
3 int arr[][];
4 List<int[]> temp;
5 public SubrectangleQueries(int[][] rectangle) {
6 arr=rectangle;
7 temp = new ArrayList<>();
8 }
9
10 public void updateSubrectangle(int row1, int col1, int row2, int col2, int newValue) {
11 temp.add(new int[]{row1,col1,row2,col2,newValue});
12 }
13
14 public int getValue(int row, int col) {
15 int result = arr[row][col];
16 for(int a[]:temp)
17 {
18 if(row>=a[0] && row<=a[2] && col>=a[1] && col<=a[3])
19 {
20 result=a[4];
21 }
22 }
23 return result;
24 }
25}
26/**
27 * Your SubrectangleQueries object will be instantiated and called as such:
28 * SubrectangleQueries obj = new SubrectangleQueries(rectangle);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected