Skip to main contentSkip to solution

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 00, not index len−1len - 1.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question