Asked inPayPal,SDE-2

Find The Sum Of The Left Leaves Problem Statement

Given a binary tree with ‘root’, your task is to find and return the sum of all the left leaf nodes.

Example:

Input:
1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1
Output:
9
Explanation:

Node 4 and Node 5 are the left leaf nodes in the tree. Node 6 is a leaf node but not a left child. Therefore, the sum is 4 + 5 = 9.

Constraints:

  • 1 ≤ T <= 10
  • 1 ≤ N <= 1000
  • Where ‘T’ is the number of test cases. ‘N’ is the number of nodes in the binary tree.
  • Time Limit: 1 sec
Note:

You do not need to print anything; this has already been taken care of. Just implement the function and return the answer.

AnswerBot
4mo

Find and return the sum of all the left leaf nodes in a binary tree.

  • Traverse the binary tree using depth-first search (DFS)

  • Check if a node is a leaf node and a left child

  • Sum up the values of all left ...read more

Help your peers!
Select
Add answer anonymously...

PayPal SDE-2 interview questions & answers

A SDE-2 was asked 10mo agoQ. Given a sorted array of integers, find the leftmost and rightmost index of a tar...read more
A SDE-2 was asked Q. Minimum Character Deletion Problem Statement You have been provided a string STR...read more
A SDE-2 was asked Q. Palindrome Checker Problem Statement Given an alphabetical string S, determine w...read more

Popular interview questions of SDE-2

A SDE-2 was asked 10mo agoQ1. Given a sorted array of integers, find the leftmost and rightmost index of a tar...read more
A SDE-2 was asked Q2. Minimum Character Deletion Problem Statement You have been provided a string STR...read more
A SDE-2 was asked Q3. Palindrome Checker Problem Statement Given an alphabetical string S, determine w...read more
PayPal SDE-2 Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits