Find the number is balanced or not
Problem to find the number balanced or not. The number length is always odd. Split the number into LHS and RHS in equal length.
if n = 1204003 120 4 003 ↓ ↓ LHS RHS The sum of the LHS = The sum of the RHS. So It's Balanced.
Example-1:
Input : n = 1204003 Output : Balanced
Example-2:
Input : n = 13522 Output : Balanced
Example-3:
Input : n = 15723 Output : Not Balanced
Solution
n = 1204003 n = str(n) a = len(n)//2 b = n[:a] c = n[a+1:] l = [] k = [] for x in b: l.append(int(x)) for y in c: k.append(int(y)) if(sum(l) == sum(k)): print("Balanced") else: print("Not Balanced")
Output
Balanced