What will this function do?
def getRear(myDeque):
if not (isEmpty()):
return myDeque[len(myDeque)-1]
else:
print("Deque Empty")
What will this function do?
def getRear(myDeque):
if not (isEmpty()):
return myDeque[len(myDeque)-1]
else:
print("Deque Empty")
Solution
✅ Correct Option: 1
The function first checks that the deque is not empty. If it has elements, it returns myDeque[len(myDeque)-1], which is the last element of the list, i.e. the rear. It only reads the value and does not change the deque. If the deque is empty, it prints "Deque Empty".
Options 2 and 4: insertion would need append() or insert(), but this function only returns a value.
Option 3: the front element would be at index , not index .
Related questions:
2025: 3 June Shift 2
2025: 15 May Shift 2
2026: 23 May Shift 2
2026: 21 May Shift 1