You are viewing a single comment's thread. Return to all comments →
Looks good! To make this even faster, you should loop through n/2 items and swap a[i] with a[n-1-i].
can you show this using codes?
I have my code submitted above in the discussion area.
My way permanently makes it reverse. If the interviewer asked to reverse the array, then this solution would not work since it does not reverse it, but it prints it in reverse. If they just want it to print in reverse, then rajarshi356's works fine.
for i in range(0, n//2):
temp = arr[i]
arr[i] = arr[-1-i]
arr[-1-i] = temp
result = ""
for i in arr:
result = result + str(i) + " "
Don't this add more operations to the logic.
n = int(raw_input().strip())
arr = map(int,raw_input().strip().split(' '))
for i in range(n):
the using code donètwork it only show the secret page help plz