Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def CheckIncrease(lst):
- '''
- This function returns the number of times an integer is followed immediately
- by a bigger integer in lst.
- For example, if lst = [1, 2, 1, 3, 4] then this function returns 3 since
- 1 followed by 2 is the first time an integer is immediately followed by a bigger integer
- 1 followed by 3 is the second time this hapens
- and 3 followed by 4 is the last and final time an integer is followed by a bigger integer
- Hence this function returns 3.
- More test cases listed below in main function along with
- their expected output (inside comments)
- '''
- count = 0
- for i in range(0,len(lst)-1):
- if(lst[i+1] > lst[i]):
- count +=1
- return count
- def main():
- print(CheckIncrease([1, 2, 3, 4, 5])) ## 4
- print(CheckIncrease([1, 2, 2, 2, 2])) ## 1
- print(CheckIncrease([2, 2, 2, 2, 2, 2])) ## 0
- print(CheckIncrease([1, 2, 2, 2, 2, 3, 3, 3, 3])) ## 2
- print(CheckIncrease([1, 2, 2, 2, 1, 3, 3, 3, 1])) ## 2
- print(CheckIncrease([100, 50, 25, 12, 6, 3, 1])) ## 0
- print(CheckIncrease([1, 2, 1, 3, 4])) ## 3
- print(CheckIncrease([])) ## 0
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement