Find the balanced node in a Linked List

Given a linked list, the task is to find the balanced node in a linked list. A balanced node is a node where the sum of all the nodes on its left is equal to the sum of all the node on its right, if no such node is found then print -1.


Input: 1 -> 2 -> 7 -> 10 -> 1 -> 6 -> 3 -> NULL
Output: 10
Sum of nodes on the left of 10 is 1 + 2 + 7 = 10
And, to the right of 10 is 1 + 6 + 3 = 10

Input: 1 -> 5 -> 5 -> 10 -> -3 -> NULL
Output: -1


  • First, find the total sum of the all node values.
  • Now, traverse the linked list one by one and while traversing keep track of all the previous nodes value sum and find the sum of the remaining node by subtracting current node value and the sum of the previous nodes value from the total sum.
  • Compare both the sums, if they are equal then current node is the required node else print -1.

Below is the implementation of the above approach:





# Python3 implementation of the approach
import sys
import math
# Structure of a node of linked list 
class Node:
    def __init__(self, data): = None = data
# Push the new node to front of the linked list
def push(head, data):
    # Return new node as head if head is empty
    if not head:
        return Node(data)
    temp = Node(data) = head
    head = temp
    return head
# Function to find the balanced node
def findBalancedNode(head):
    tsum = 0
    curr_node = head
    # Traverse through all node 
    # to find the total sum
    while curr_node:
        curr_node =
    # Set current_sum and remaining sum to zero 
    current_sum, remaining_sum = 0, 0
    curr_node = head
    # Traversing the list to check balanced node
        remaining_sum = tsum-(current_sum +
        # If sum of the nodes on the left and the current node 
        # is equal to the sum of the nodes on the right
        if current_sum == remaining_sum:
        curr_node =
    return -1
# Driver code
if __name__=='__main__':
    head = None
    head = push(head, 3)
    head = push(head, 6)
    head = push(head, 1)
    head = push(head, 10)
    head = push(head, 7)
    head = push(head, 2)
    head = push(head, 1)




Time Complexity: O(n)

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.