📘 Introduction to Arrays

🧠 What is an Array?

An array is a linear data structure that stores a fixed-size sequence of elements of the same type in contiguous memory locations. Arrays allow efficient random access via indexing and are foundational in many algorithmic solutions.


🛠️ Array Basics

✅ Declaration and Initialization

arr = [10, 20, 30, 40]

✅ Accessing Elements

print(arr[0])  # Output: 10

✅ Updating Elements

arr[2] = 99

⚙️ Basic Array Operations

Operation Time Complexity
Access by index \(O(1)\)
Update by index \(O(1)\)
Insert at end \(O(1)\) (amortized for dynamic arrays)
Insert at index \(O(n)\)
Delete by index \(O(n)\)
Search (linear) \(O(n)\)

🔍 Understanding Memory Layout

Arrays are stored in contiguous blocks in memory, enabling constant-time access using the index:

arr[3] → Base Address + 3 × Size_of_Element

👉 This is why arrays are faster than linked lists for indexed access.


📊 Types of Arrays

  • 1D Array: Single row of elements — arr[5]
  • 2D Array: Matrix/grid — matrix[3][3]
  • Multidimensional Arrays: Arrays within arrays

🧪 Example Problems

🔹 Problem 1: Find Maximum Element in an Array

arr = [2, 5, 1, 9, 3]
max_val = arr[0]
for num in arr:
    if num > max_val:
        max_val = num
print(max_val)

🔹 Problem 2: Reverse an Array In-Place

arr = [1, 2, 3, 4, 5]
start = 0
end = len(arr) - 1
while start < end:
    arr[start], arr[end] = arr[end], arr[start]
    start += 1
    end -= 1
print(arr)

✍️ Practice Assignments

  1. Write a program to calculate the sum and average of elements in an array.

  2. Find the second largest element in an array.

  3. Implement a program to remove all negative numbers from an array.

  4. Practice accessing and updating values in a 2D array.


🔔 Next : We’ll dive into array problem-solving patterns like prefix sums, two-pointer technique, and sliding window.


📚 Practice Problems

Below you’ll find all array and string problems organized by technique and difficulty. Master each pattern systematically!

🎯 Problems by Technique

🔹 Two pointer


🔹 Array


🔹 Dynamic programming

Easy

No problems yet

Medium

No problems yet


🔹 Sliding window


🔹 Deque

Easy

No problems yet

Medium

No problems yet


🔹 Monotonic queue

Easy

No problems yet

Medium

No problems yet


🔹 Heap

Easy

No problems yet

Medium

No problems yet


🔹 Priority queue

Easy

No problems yet

Medium

No problems yet


🔹 Divide and conquer

Easy

No problems yet

Hard

No problems yet


🔹 Hashmap

Easy

No problems yet

Medium

No problems yet


🔹 String

Easy

No problems yet

Medium

Hard

No problems yet


🔹 Pattern matching

Easy

No problems yet

Medium

Hard

No problems yet


🔹 Kmp

Easy

No problems yet

Medium

Hard

No problems yet


📊 Problems by Phase

🎓 String Manipulation

Easy

No problems yet

Medium

Hard

No problems yet


📈 All Problems by Difficulty

Easy Problems

Medium Problems

Hard Problems


🎯 Learning Path Recommendation

  1. Start with Two Pointers - Master the basics of array manipulation
  2. Move to Sliding Window - Learn to optimize subarray problems
  3. Practice Prefix Sum - Understand cumulative techniques
  4. Tackle String Manipulation - Apply patterns to string problems
  5. Challenge yourself - Combine multiple techniques in harder problems

Table of contents