- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Program to check sublist sum is strictly greater than the total sum of given list Python

Suppose we have a list of numbers called nums, we have to check whether there is a sublist such that its sum is strictly greater than the total sum of the list.

So, if the input is like nums = [1, −2, 3, 4], then the output will be True, as the sum of the list is 6 and the sum of the sublist [3, 5] is 8 which is strictly larger.

To solve this, we will follow these steps −

total := sum of elements nums

s := 0

for each i in nums, do

s := s + i

if s < 0, then

return True

s := 0

i := size of nums − 1

while i > −1, do

s := s + nums[i]

if s < 0, then

return True

i := i − 1

return False

Let us see the following implementation to get better understanding −

## Example

class Solution: def solve(self, nums): total = sum(nums) s = 0 for i in nums: s += i if s < 0: return True s = 0 i = len(nums) − 1 while i > −1: s += nums[i] if s < 0: return True i = i − 1 return False ob1 = Solution() nums = [2, -4, 3, 5] print(ob1.solve(nums))

## Input

[2, −4, 3, 5]

## Output

True

- Related Articles
- Program to find lowest sum of pairs greater than given target in Python
- Program to check whether list is strictly increasing or strictly decreasing in Python
- Program to find sum of contiguous sublist with maximum sum in Python
- Program to find sum of the minimums of each sublist from a list in Python
- Python Program to Find the Total Sum of a Nested List Using Recursion
- Program to find the maximum sum of circular sublist in Python
- Program to find the sum of largest K sublist in Python
- Program to convert one list identical to other with sublist sum operation in Python
- Python program to check if all the values in a list that are greater than a given value
- Program to find length of contiguous strictly increasing sublist in Python
- Program to find length of longest sublist whose sum is 0 in Python
- Program to split lists into strictly increasing sublists of size greater than k in Python
- Program to check if all the values in a list that are greater than a given value in Python
- Check if list is strictly increasing in Python
- Python – Extract dictionaries with values sum greater than K

Advertisements