Hướng dẫn how do you find the sum of an odd number in an array in python? - làm thế nào để bạn tìm thấy tổng của một số lẻ trong một mảng trong python?

Điều này có thể được thực hiện với isinstance, điều này mạnh mẽ chống lại những thứ như các lớp con:

def _oddsum[n]:
    # efficient generator expression here
    return sum[i for i in range[n + 1] if i % 2 == 1]

def oddsum[arr]:
    return [_oddsum[n] for n in arr]

def polymorph_oddsum[x]:
    if isinstance[x, list]:
        return oddsum[x]
    return _oddsum[x]

if __name__ == "__main__":
    # really all of these are more sensible ways to do this
    print[oddsum[[9]]]
    print[_oddsum[9]]
    print[oddsum[[4, 5, 9]]]
    print[oddsum[[4, 5, 9]]]
    print[oddsum[{4, 5, 9}]]

    # but if you really wanted, you can use polymorph_oddsum for either case
    print[polymorph_oddsum[9]]
    print[polymorph_oddsum[[4, 5, 9]]]

Tuy nhiên, như bạn có thể thấy từ những bình luận của tôi, đây có lẽ thực sự không phải là điều bạn muốn làm. Bạn chỉ nên gọi chức năng thích hợp tùy thuộc vào loại đầu vào của bạn sẽ là gì, mà bạn thực sự nên biết trước khi chạy.

Cách tiếp cận isinstance ít được mong muốn hơn vì nó bị hỏng ngay khi bạn cho nó bất kỳ loại nào khác có thể khác, mặc dù oddsum bình thường không, như mã của tôi cho thấy.

Ngẫu nhiên, trong khi tôi đã tự do đưa vòng lặp của bạn vào một biểu thức máy phát duy nhất, bạn thậm chí không cần một vòng lặp ở đây. Tổng số lẻ là một tiến trình dễ dàng để tìm một biểu mẫu đóng cho và bạn chỉ có thể sử dụng

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2

Điều kiện tiên quyết - cơ bản mảng & nbsp; đưa ra một mảng, viết một chương trình để tìm tổng các giá trị của các vị trí chỉ số chẵn và lẻ một cách riêng biệt.
Given an array, write a program to find the sum of values of even and odd index positions separately.

Examples: 

Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 

Implementation:

C++

#include

using

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
0
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
1

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
2
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
3
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
5
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
7

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
8

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
1

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
4

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
6
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
7
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
9

Even index positions sum 9
Odd index positions sum 12
0
Even index positions sum 9
Odd index positions sum 12
1
Even index positions sum 9
Odd index positions sum 12
2

Even index positions sum 9
Odd index positions sum 12
3
Even index positions sum 9
Odd index positions sum 12
4

Even index positions sum 9
Odd index positions sum 12
0
Even index positions sum 9
Odd index positions sum 12
6

Even index positions sum 9
Odd index positions sum 12
3
Even index positions sum 9
Odd index positions sum 12
8

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Even index positions sum 9
Odd index positions sum 12
0

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Even index positions sum 9
Odd index positions sum 12
60
Even index positions sum 9
Odd index positions sum 12
3
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
27

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Even index positions sum 9
Odd index positions sum 12
60
Even index positions sum 9
Odd index positions sum 12
65
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
43
Even index positions sum 9
Odd index positions sum 12
67
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
31

Even index positions sum 9
Odd index positions sum 12
0

Đầu ra

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
8

Độ phức tạp về thời gian: O [n] trong đó n không có phần tử trong không gian arrayauxiliary nhất định: 0 [1]

Bài viết này được đóng góp bởi Rishabh Jain. Nếu bạn thích GeekSforGeeks và muốn đóng góp, bạn cũng có thể viết một bài viết bằng Write.GeekSforGeek.org hoặc gửi bài viết của bạn. Xem bài viết của bạn xuất hiện trên trang chính của GeekSforGeek và giúp các chuyên viên máy tính khác.

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9isinstance4

Điều kiện tiên quyết - cơ bản mảng & nbsp; đưa ra một mảng, viết một chương trình để tìm tổng các giá trị của các vị trí chỉ số chẵn và lẻ một cách riêng biệt.

Even index positions sum 9
Odd index positions sum 12
0

using
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
0
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
1

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
2
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
3
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
5
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
7

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
8

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
1

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
8

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
4

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
6
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
7
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
9

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Even index positions sum 9
Odd index positions sum 12
2
Even index positions sum 9
Odd index positions sum 12
3
Even index positions sum 9
Odd index positions sum 12
4

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Even index positions sum 9
Odd index positions sum 12
2
Even index positions sum 9
Odd index positions sum 12
7
Even index positions sum 9
Odd index positions sum 12
8

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
16
Even index positions sum 9
Odd index positions sum 12
4

Even index positions sum 9
Odd index positions sum 12
3
Even index positions sum 9
Odd index positions sum 12
6

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
16
Even index positions sum 9
Odd index positions sum 12
8

Even index positions sum 9
Odd index positions sum 12
0
Even index positions sum 9
Odd index positions sum 12
0

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4 isinstance1

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4 isinstance5

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Even index positions sum 9
Odd index positions sum 12
0

Even index positions sum 9
Odd index positions sum 12
0

Python3

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4 isinstance8isinstance9isinstance0isinstance9isinstance2

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9isinstance6 isinstance7

Java

isinstance9 oddsum0

oddsum1 oddsum2

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9oddsum4 oddsum5
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
2 oddsum7

Even index positions sum 9
Odd index positions sum 12
0
Even index positions sum 9
Odd index positions sum 12
6
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
59

Even index positions sum 9
Odd index positions sum 12
0
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4 #include 2#include 3#include 4#include 5#include 4#include 7#include 4#include 9#include 4using1

Even index positions sum 9
Odd index positions sum 12
0____14 using7using8using9using8____101

Even index positions sum 9
Odd index positions sum 12
0____26
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
7
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
06using8
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
08

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
83
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
39
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
85#include 3#include 4#include 5#include 4#include 7#include 4#include 9__

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
98
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
39
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
00____
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
01

Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
02

C#

using

Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
04

oddsum4 oddsum1

Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
07

Even index positions sum 9
Odd index positions sum 12
3
Even index positions sum 9
Odd index positions sum 12
1
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
11#include 5
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
13using8
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
15

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
8

Even index positions sum 9
Odd index positions sum 12
0
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
17

Even index positions sum 9
Odd index positions sum 12
0
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
25
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
26
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
27

Even index positions sum 9
Odd index positions sum 12
0
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
25
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
30
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
31

Even index positions sum 9
Odd index positions sum 12
0
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
8

Even index positions sum 9
Odd index positions sum 12
3
Even index positions sum 9
Odd index positions sum 12
1
Even index positions sum 9
Odd index positions sum 12
2

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
16
Even index positions sum 9
Odd index positions sum 12
4

Even index positions sum 9
Odd index positions sum 12
3
Even index positions sum 9
Odd index positions sum 12
6

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
16
Even index positions sum 9
Odd index positions sum 12
8

Even index positions sum 9
Odd index positions sum 12
0
Even index positions sum 9
Odd index positions sum 12
0

Even index positions sum 9
Odd index positions sum 12
0
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
40
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
41

Even index positions sum 9
Odd index positions sum 12
0
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
40
Even index positions sum 9
Odd index positions sum 12
67
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
31

Even index positions sum 9
Odd index positions sum 12
0
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
40
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
48

Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
49
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
43
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
51
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
31

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Even index positions sum 9
Odd index positions sum 12
0

Even index positions sum 9
Odd index positions sum 12
0

PHP

Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
56

Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
57
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
3
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
59#include 4
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
61
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
15

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
8

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
65
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
66

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
68
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
66

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
6
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
7
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
73
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
74__

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
8

Even index positions sum 9
Odd index positions sum 12
0
Even index positions sum 9
Odd index positions sum 12
1
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
7
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
73
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
87

Even index positions sum 9
Odd index positions sum 12
3
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
65
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
90
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
59
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
85
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
73
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
94

Even index positions sum 9
Odd index positions sum 12
0
Even index positions sum 9
Odd index positions sum 12
6

Even index positions sum 9
Odd index positions sum 12
3
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
68
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
90
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
59
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
85
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
73
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
94

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Even index positions sum 9
Odd index positions sum 12
0

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Even index positions sum 9
Odd index positions sum 12
07
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
7
Even index positions sum 9
Odd index positions sum 12
3
Even index positions sum 9
Odd index positions sum 12
10
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
65
Even index positions sum 9
Odd index positions sum 12
12

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Even index positions sum 9
Odd index positions sum 12
07
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
7
Even index positions sum 9
Odd index positions sum 12
7
Even index positions sum 9
Odd index positions sum 12
10
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
68
Even index positions sum 9
Odd index positions sum 12
12

Even index positions sum 9
Odd index positions sum 12
0

Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
59
Even index positions sum 9
Odd index positions sum 12
222____323
Even index positions sum 9
Odd index positions sum 12
24

Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
61
Even index positions sum 9
Odd index positions sum 12
26
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
59
Even index positions sum 9
Odd index positions sum 12
12

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
3
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
59#include 4
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
61
Even index positions sum 9
Odd index positions sum 12
12

Even index positions sum 9
Odd index positions sum 12
34

JavaScript

Even index positions sum 9
Odd index positions sum 12
35

Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
57
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
02

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
8

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Even index positions sum 9
Odd index positions sum 12
40

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Even index positions sum 9
Odd index positions sum 12
42

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
6
Even index positions sum 9
Odd index positions sum 12
45

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
8

Even index positions sum 9
Odd index positions sum 12
0
Even index positions sum 9
Odd index positions sum 12
1
Even index positions sum 9
Odd index positions sum 12
2

Even index positions sum 9
Odd index positions sum 12
3
Even index positions sum 9
Odd index positions sum 12
4

Even index positions sum 9
Odd index positions sum 12
0
Even index positions sum 9
Odd index positions sum 12
6

Even index positions sum 9
Odd index positions sum 12
3
Even index positions sum 9
Odd index positions sum 12
8

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Even index positions sum 9
Odd index positions sum 12
0

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Even index positions sum 9
Odd index positions sum 12
60
Even index positions sum 9
Odd index positions sum 12
3
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
27

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Even index positions sum 9
Odd index positions sum 12
60
Even index positions sum 9
Odd index positions sum 12
65
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
43
Even index positions sum 9
Odd index positions sum 12
67
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
31

Even index positions sum 9
Odd index positions sum 12
0

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Even index positions sum 9
Odd index positions sum 12
71

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Even index positions sum 9
Odd index positions sum 12
73

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9isinstance4

Even index positions sum 9
Odd index positions sum 12
76

Đầu ra

Even index positions sum 9
Odd index positions sum 12

Độ phức tạp về thời gian: O [chiều dài [mảng]] Không gian phụ trợ: 0 [1] O[length[arr]]
Auxiliary Space: 0[1]

Phương pháp 2: Sử dụng cắt lát trong Python:

Tính tổng của tất cả các chỉ số thậm chí bằng cách sử dụng cắt và lặp lại giống nhau với các chỉ số lẻ và tổng in.

Dưới đây là việc thực hiện:

C++

#include

using

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
0
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
1

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
3
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4
Even index positions sum 9
Odd index positions sum 12
84
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
7

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
8

Even index positions sum 9
Odd index positions sum 12
88
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
1

Even index positions sum 9
Odd index positions sum 12
88
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
4

Even index positions sum 9
Odd index positions sum 12
88
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
6
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
7
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
9

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Even index positions sum 9
Odd index positions sum 12
1
Even index positions sum 9
Odd index positions sum 12
2

Even index positions sum 9
Odd index positions sum 12
02
Even index positions sum 9
Odd index positions sum 12
4

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Even index positions sum 9
Odd index positions sum 12
6

Even index positions sum 9
Odd index positions sum 12
02
Even index positions sum 9
Odd index positions sum 12
8

Even index positions sum 9
Odd index positions sum 12
88
Even index positions sum 9
Odd index positions sum 12
0

Even index positions sum 9
Odd index positions sum 12
88
Even index positions sum 9
Odd index positions sum 12
11
Even index positions sum 9
Odd index positions sum 12
3
Even index positions sum 9
Odd index positions sum 12
13
Even index positions sum 9
Odd index positions sum 12
14
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
01

Even index positions sum 9
Odd index positions sum 12
88
Even index positions sum 9
Odd index positions sum 12
11
Even index positions sum 9
Odd index positions sum 12
67
Even index positions sum 9
Odd index positions sum 12
19

Even index positions sum 9
Odd index positions sum 12
0

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4 isinstance1

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
8

Even index positions sum 9
Odd index positions sum 12
88
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4 isinstance5

Even index positions sum 9
Odd index positions sum 12
88
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4
Even index positions sum 9
Odd index positions sum 12
29isinstance9
Even index positions sum 9
Odd index positions sum 12
31isinstance9isinstance2

Even index positions sum 9
Odd index positions sum 12
88isinstance4

Even index positions sum 9
Odd index positions sum 12
0

Java

isinstance9 oddsum0

oddsum1

Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
07

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9oddsum5
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
2
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
3
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4
Even index positions sum 9
Odd index positions sum 12
46
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
7

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
8

Even index positions sum 9
Odd index positions sum 12
0__14 using7using8
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
01

Even index positions sum 9
Odd index positions sum 12
0__14
Even index positions sum 9
Odd index positions sum 12
58using8
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
01

Even index positions sum 9
Odd index positions sum 12
0____26
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
7
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
06using8
Even index positions sum 9
Odd index positions sum 12
67

Even index positions sum 9
Odd index positions sum 12
3
Even index positions sum 9
Odd index positions sum 12
1
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
11#include 5
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
13using8
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
15

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
16
Even index positions sum 9
Odd index positions sum 12
4

Even index positions sum 9
Odd index positions sum 12
3
Even index positions sum 9
Odd index positions sum 12
6

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
16
Even index positions sum 9
Odd index positions sum 12
8

Even index positions sum 9
Odd index positions sum 12
0
Even index positions sum 9
Odd index positions sum 12
0

Even index positions sum 9
Odd index positions sum 12
0
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
25
Even index positions sum 9
Odd index positions sum 12
3

Even index positions sum 9
Odd index positions sum 12
86
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
27

Even index positions sum 9
Odd index positions sum 12
0
Even index positions sum 9
Odd index positions sum 12
89
Even index positions sum 9
Odd index positions sum 12
67
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
31

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Even index positions sum 9
Odd index positions sum 12
0

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9oddsum4 oddsum5
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
2
Even index positions sum 9
Odd index positions sum 12
98

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
8

Các

Even index positions sum 9
Odd index positions sum 12
0
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4 isinstance18

Even index positions sum 9
Odd index positions sum 12
0isinstance4

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Even index positions sum 9
Odd index positions sum 12
0

Even index positions sum 9
Odd index positions sum 12
0

Python3

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
35
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
36

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9isinstance27
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
39 isinstance29isinstance30#include 55____532

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9isinstance34
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
39 isinstance29isinstance37#include 3isinstance39#include 55532

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
74
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
7isinstance45isinstance46

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
74
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
7isinstance50isinstance51

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
83
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
39
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
85#include 3#include 4#include 5#include 4#include 7#include 4#include 9__

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
98
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
39
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
00____
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
01

Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
02

C#

using

Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
04

oddsum4 oddsum1

Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
07

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9oddsum5
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
2
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
3
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4
Even index positions sum 9
Odd index positions sum 12
46
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
7

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
8

Even index positions sum 9
Odd index positions sum 12
0__14 using7using8
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
01

Even index positions sum 9
Odd index positions sum 12
0__14
Even index positions sum 9
Odd index positions sum 12
58using8
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
01

Even index positions sum 9
Odd index positions sum 12
0____26
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
7
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
06using8
Even index positions sum 9
Odd index positions sum 12
67

Even index positions sum 9
Odd index positions sum 12
3
Even index positions sum 9
Odd index positions sum 12
1
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
11#include 5
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
13using8
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
15

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
16
Even index positions sum 9
Odd index positions sum 12
4

Even index positions sum 9
Odd index positions sum 12
3
Even index positions sum 9
Odd index positions sum 12
6

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
16
Even index positions sum 9
Odd index positions sum 12
8

Even index positions sum 9
Odd index positions sum 12
0
Even index positions sum 9
Odd index positions sum 12
0

Even index positions sum 9
Odd index positions sum 12
0
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
40
Even index positions sum 9
Odd index positions sum 12
3

isinstance12

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
27

Even index positions sum 9
Odd index positions sum 12
0
Even index positions sum 9
Odd index positions sum 12
0

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Even index positions sum 9
Odd index positions sum 12
0

Even index positions sum 9
Odd index positions sum 12
0
Even index positions sum 9
Odd index positions sum 12
89
Even index positions sum 9
Odd index positions sum 12
67
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
31

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9oddsum4 oddsum5
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
2
Even index positions sum 9
Odd index positions sum 12
98

Even index positions sum 9
Odd index positions sum 12
0
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
4
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
17

Các

Even index positions sum 9
Odd index positions sum 12
0isinstance4

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Even index positions sum 9
Odd index positions sum 12
0

Even index positions sum 9
Odd index positions sum 12
0

JavaScript

Even index positions sum 9
Odd index positions sum 12
35

Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
57
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
02

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
8

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Even index positions sum 9
Odd index positions sum 12
40

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Even index positions sum 9
Odd index positions sum 12
42

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
6
Even index positions sum 9
Odd index positions sum 12
45

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
8

Even index positions sum 9
Odd index positions sum 12
0
Even index positions sum 9
Odd index positions sum 12
1
Even index positions sum 9
Odd index positions sum 12
2

Even index positions sum 9
Odd index positions sum 12
3
Even index positions sum 9
Odd index positions sum 12
4

Even index positions sum 9
Odd index positions sum 12
0
Even index positions sum 9
Odd index positions sum 12
6

Even index positions sum 9
Odd index positions sum 12
3
Even index positions sum 9
Odd index positions sum 12
8

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Even index positions sum 9
Odd index positions sum 12
0

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Even index positions sum 9
Odd index positions sum 12
60
Even index positions sum 9
Odd index positions sum 12
3
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
27

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Even index positions sum 9
Odd index positions sum 12
60
Even index positions sum 9
Odd index positions sum 12
65
Input : arr = {1, 2, 3, 4, 5, 6}
Output :Even index positions sum 9
        Odd index positions sum 12
Explanation: Here, n = 6 so there will be 3 even 
index positions and 3 odd index positions in an array
Even = 1 + 3 + 5 = 9
Odd =  2 + 4 + 6 = 12

Input : arr = {10, 20, 30, 40, 50, 60, 70}
Output : Even index positions sum 160
        Odd index positions sum 170
Explanation: Here, n = 7 so there will be 3 odd
index positions and 4 even index positions in an array
Even = 10 + 30 + 50 + 70 = 160
Odd = 20 + 40 + 60 = 120 
43
Even index positions sum 9
Odd index positions sum 12
67
def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
31

Even index positions sum 9
Odd index positions sum 12
0

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Even index positions sum 9
Odd index positions sum 12
71

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9
Even index positions sum 9
Odd index positions sum 12
73

def _oddsum2[n]:
    return [[n + 1] // 2] ** 2
9isinstance4

Even index positions sum 9
Odd index positions sum 12
76

Đầu ra

Even index positions sum 9
Odd index positions sum 12

Độ phức tạp về thời gian: O [n] trong đó n không có phần tử trong không gian arrayauxiliary nhất định: 0 [1]O[n] where n is no of elements in given array
Auxiliary Space: 0[1]

Bài viết này được đóng góp bởi Rishabh Jain.Nếu bạn thích GeekSforGeeks và muốn đóng góp, bạn cũng có thể viết một bài viết bằng Write.GeekSforGeek.org hoặc gửi bài viết của bạn.Xem bài viết của bạn xuất hiện trên trang chính của GeekSforGeek và giúp các chuyên viên máy tính khác.Rishabh Jain. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to . See your article appearing on the GeeksforGeeks main page and help other Geeks.


Bài Viết Liên Quan

Chủ Đề