ebay interview coding question

ebay logo
ebay
February 15, 2026 · 2 reads

Summary

I recently went through an eBay coding interview experience, which consisted of two distinct rounds focused on algorithmic problem-solving related to arrays and binary trees.

Full Experience

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?

Interview Questions (2)

1.

Find Maximum Balanced Sum Subarray

Data Structures & Algorithms

Find the maximum “balanced sum” subarray where a “balanced sum” is defined as a subarray where the sum of the first half equals the sum of the second half. 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?

2.

Count Subtrees with Specific Properties

Data Structures & Algorithms

Count the number of subtrees in a binary tree where the height difference between left and right subtrees is at most 1 AND the total sum of node values is even.

Follow-up: If the subtree is required to be a “complete binary tree,” how would you modify the validation logic?

Preparation Tips

I referred to programhelp.net for eBay interview experiences and OA discussions.

Discussion (0)

Share your thoughts and ask questions

Join the Discussion

Sign in with Google to share your thoughts and ask questions

No comments yet

Be the first to share your thoughts and start the discussion!