juniorArrays
How do you insert an element into an array?
Updated Apr 28, 2026
Short answer
Insert by shifting elements and placing new value.
Deep explanation
Insertion requires shifting elements to create space, making it O(n) in worst case.
Real-world example
Adding item in middle of list.
Common mistakes
- Ignoring shifting cost.
Follow-up questions
- What is splice?
- Why O(n)?