You are given two independent coding tasks.
Task 1: In-order traversal of a binary tree
Given the root of a binary tree, return the in-order traversal of its node values.
-
In-order
means: traverse left subtree → visit node → traverse right subtree.
-
Input:
root
(may be
null
)
-
Output:
an array/list of node values in in-order
-
Constraints (typical):
up to ~10^5 nodes; values fit in 32-bit int.
Task 2: Sum of the top-left submatrix up to (x, y)
Given an m x n matrix A of integers and coordinates (x, y) (0-indexed), compute the sum of all elements in the rectangle from (0,0) to (x,y) inclusive.
Example: sum(x,y) = Σ_{i=0..x} Σ_{j=0..y} A[i][j]
-
Input:
matrix
A
, and one or more queries
(x, y)
where
0 ≤ x < m
,
0 ≤ y < n
-
Output:
for each query, return the computed sum
-
Follow-up (common):
If there are many queries, design for fast per-query time.
-
Constraints (typical):
m,n
up to ~10^3 or higher; values can be negative; sums may require 64-bit integer type.