Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,950 questions

51,892 answers

573 users

How to count the number of strictly increasing subarrays in a list with Python

1 Answer

0 votes
def countStrictlyIncreasingSubarrays(lst):
    count = 0
 
    for i in range(len(lst)):
        for j in range(i + 1, len(lst)):
            if lst[j - 1] >= lst[j]:
                break
 
            count = count + 1
 
    return count
 

# Example 1  
lst = [1, 2, 3, 4]

# {1, 2}, {1, 2, 3}, {1, 2, 3, 4}, {2, 3}, {2, 3, 4}, {3, 4}
 
print("Count of strictly increasing subarrays = ", countStrictlyIncreasingSubarrays(lst))


# Exampe 2
lst = [1, 3, 4, 0, 7, 5, 9];

# {1, 3}, {1, 3, 4}, {3, 4}, {0, 7}, {5, 9}

print("Count of strictly increasing subarrays = ", countStrictlyIncreasingSubarrays(lst))



'''
run:

Count of strictly increasing subarrays =  6
Count of strictly increasing subarrays =  5

'''

 



answered Aug 21, 2022 by avibootz
...