Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Second Last Element

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Second Last Element. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Print the 2nd last element of a reversed array.

The input array is already provided in reversed order. Implement the function to return its second-last element, meaning the value at index len(arr) - 2.

Input: A list arr containing at least two integers.

Output: The integer at the second-last position. Do not modify the input array.

Constraints

  • 2 <= len(arr) <= 10^5
  • -10^9 <= arr[i] <= 10^9
  • The input array is already in reversed order
  • The input array must not be modified

Function Signature

def second_last_reversed(arr):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output