A. Using '/' instead of '//' for middle index calculation
B. Using insert() instead of append() method
C. Not defining arr before insertion
D. Using print() incorrectly
Solution
Step 1: Check middle index calculation
len(arr) / 2 returns a float (2.5), but insert() requires an integer index.
Step 2: Correct middle index calculation
Use integer division '//' to get integer index: mid = len(arr) // 2 = 2.
Final Answer:
Using '/' instead of '//' for middle index calculation -> Option A
Quick Check:
Index must be int, use '//' not '/' [OK]
Hint: Use '//' for integer division to get valid index [OK]
Common Mistakes:
Using '/' causing TypeError
Forgetting to calculate middle index
Using append() instead of insert()
5. Given arr = [2, 4, 6, 8, 10, 12], write code to insert the value 7 exactly in the middle so that the array remains sorted. What will be the final array?
hard
A. [2, 4, 7, 6, 8, 10, 12]
B. [2, 4, 6, 8, 7, 10, 12]
C. [7, 2, 4, 6, 8, 10, 12]
D. [2, 4, 6, 7, 8, 10, 12]
Solution
Step 1: Calculate middle index for even length array
Length is 6, middle index = 6 // 2 = 3.
Step 2: Insert 7 at index 3 to keep array sorted
Inserting 7 at index 3 places it between 6 and 8, maintaining sorted order.
Final Answer:
[2, 4, 6, 7, 8, 10, 12] -> Option D
Quick Check:
Insert 7 at middle index 3 to keep sorted [OK]
Hint: Insert at middle index to keep sorted order [OK]
Common Mistakes:
Inserting 7 at wrong index breaking order
Appending 7 at end
Inserting 7 at start
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.