I tried to reverse an array in Python, but I got an IndexError: list index out of range. Can anyone help me find out what's my problem?
Here's my code:
def reverseArray(a,n):
b = []
for i in range(n + 1):
b.insert(0, a[i])
return b
Error:
Traceback (most recent call last):
File "/tmp/submission/20220709/03/24/hackerrank-6dc9d7d54d580ec91f519f2a6455587b/code/Solution.py", line 33, in <module>
res = reverseArray(arr,arr_count)
File "/tmp/submission/20220709/03/24/hackerrank-6dc9d7d54d580ec91f519f2a6455587b/code/Solution.py", line 21, in reverseArray
b.insert(0, a[i])
IndexError: list index out of range