-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsumgroups.py
41 lines (31 loc) · 974 Bytes
/
sumgroups.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
Task
Given an array of integers, sum consecutive even numbers and consecutive odd numbers. Repeat the process while it can
be done and return the length of the final array.
Example
For arr = [2, 1, 2, 2, 6, 5, 0, 2, 0, 5, 5, 7, 7, 4, 3, 3, 9]
The result should be 6.
[2, 1, 2, 2, 6, 5, 0, 2, 0, 5, 5, 7, 7, 4, 3, 3, 9] -->
2+2+6 0+2+0 5+5+7+7 3+3+9
[2, 1, 10, 5, 2, 24, 4, 15 ] -->
2+24+4
[2, 1, 10, 5, 30, 15 ]
The length of final array is 6
Input/Output
[input] integer array arr
A non-empty array,
1 ≤ arr.length ≤ 1000
0 ≤ arr[i] ≤ 1000
[output] an integer
The length of the final array
"""
def sum_groups(arr):
start = True
even_lst = []
odd_lst = []
while start == True:
for i in range(len(arr)):
if arr[i]%2 == 0:
even_lst.append(i)
else:
odd_lst.append(i)