ebay interview coding question

706
Feb 15, 2026

Coding:

r1: Array problem — Find the maximum “balanced sum” subarray
Idea: A “balanced sum” is defined as a subarray where the sum of the first half equals the sum of the second half. First, preprocess a prefix sum array. Then iterate over all possible subarray midpoints and use the prefix sums to efficiently compute the sums of the left and right halves. Track the maximum length (or sum) that satisfies the condition. Note that the subarray length must be even.
Follow-up: If one “adjustable element” is allowed within the subarray, how would you find the subarray with the maximum balanced sum?

r2: Binary tree problem — Count the number of subtrees where the height difference between left and right subtrees is at most 1 and the total sum of node values is even
Idea: Use postorder traversal of the binary tree. For each subtree, compute and return its height and the sum of its node values. During traversal, check whether the subtree satisfies both conditions and increment the counter accordingly. Be careful with the initialization rules for height and sum of null nodes.
Follow-up: If the subtree is required to be a “complete binary tree,” how would you modify the validation logic?

You can refer to this for eBay interview experiences and OA discussions for more details.

Comments (0)