📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!

  • google app store apple app store
  • ✖

      Question

      Consider the array arr = [1, 2, 3, 4, 5] and the

      following operations: 1.  arr.insert(2, 9) (inserts 9 at index 2) 2.  arr.pop(3) (removes element at index 3) What is the final state of the array arr after these operations?
      A [1, 2, 9, 4, 5] Correct Answer Incorrect Answer
      B [1, 2, 9, 5] Correct Answer Incorrect Answer
      C [1, 9, 2, 4, 5] Correct Answer Incorrect Answer
      D [1, 9, 2, 5] Correct Answer Incorrect Answer
      E [1, 2, 3, 9, 5] Correct Answer Incorrect Answer

      Solution

      Initial: [1, 2, 3, 4, 5] 1. arr.insert(2, 9): [1, 2, 9, 3, 4, 5] (index 0=1, 1=2, 2=9, 3=3, 4=4, 5=5) 2. arr.pop(3): removes element at index 3, which is 3.    Result: [1, 2, 9, 4, 5]

      Practice Next
      ask-question