Python: List of integers where the sum of the first i integers is i
Sum of First i Equals i
Write a Python program to check a given list of integers where the sum of the first i integers is i.
Input: [0, 1, 2, 3, 4, 5] Output: False Input: [1, 1, 1, 1, 1, 1] Output: True Input: [2, 2, 2, 2, 2] Output: False
Sample Solution:
Python Code:
Sample Output:
Original list: [0, 1, 2, 3, 4, 5] Check the said list, where the sum of the first i integers is i: i = 1 False Original list: [0, 1, 2, 3, 4, 5] Check the said list, where the sum of the first i integers is i: i = 3 True Original list: [1, 1, 1, 1, 1, 1] Check the said list, where the sum of the first i integers is i: i = 6 True Original list: [2, 2, 2, 2, 2] Check the said list, where the sum of the first i integers is i: i = 2 False
Flowchart:

For more Practice: Solve these Related Problems:
- Write a Python program to check if the cumulative sum of the first i elements of a list equals i for each i, using iterative summation.
- Write a Python program that uses list slicing to verify that the sum of the first i numbers equals i for every valid i in the list.
- Write a Python program to determine if a list of integers satisfies the condition by computing the cumulative sum and comparing to an arithmetic series.
- Write a Python program to implement the check recursively by verifying the condition for the first element and then for the remainder of the list.
Python Code Editor :
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Find a list of one hundred integers between 0 and 999 which all differ by ten from one another.
Next: Split a string of words separated by commas and spaces into 2 lists: words and separators.
What is the difficulty level of this exercise?
Based on 136 votes, average difficulty level of this exercise is Medium
.
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics