💡
Exercise 6

Array Basics 10 XP Easy

Ctrl+Enter Run Ctrl+S Save

Welcome to Arrays — the most fundamental data structure in all of programming! 📚

💡 Think of it like this: An array is like a row of lockers in a school hallway. Each locker has a number (index), and each locker holds one item. You can quickly open any locker if you know its number!

# Creating arrays (Python uses lists) nums = [10, 20, 30, 40, 50] # Accessing by index (starts at 0!) print(nums[0]) # 10 (first element) print(nums[2]) # 30 (third element) print(nums[-1]) # 50 (last element) # Length print(len(nums)) # 5

Key array operations and their Big O:

  • Access by index → O(1) — instant! Just go to that locker
  • Append to end → O(1) — add at the end
  • ⚠️ Insert at beginning/middle → O(n) — everyone has to shift over!
  • ⚠️ Search for a value → O(n) — check every locker one by one
  • Update by index → O(1) — change what's in a specific locker

Arrays are used in almost EVERY coding interview question. Master arrays and you master half of DSA! 💪

📋 Instructions
Write a function `array_operations(arr)` that takes a list of integers and returns a dictionary with: - `'sum'` — sum of all elements - `'min'` — minimum element - `'max'` — maximum element - `'length'` — number of elements - `'reversed'` — the list reversed Print the result for the test case.
Use Python built-ins: sum(arr), min(arr), max(arr), len(arr). For reversed, use arr[::-1] which creates a reversed copy. Return them all in a dictionary: {'sum': sum(arr), ...}
🧪 Test Cases
Input
f"Sum: {result['sum']}"
Expected
Sum: 28
Test case 1
Input
f"Min: {result['min']}"
Expected
Min: 1
Test case 2
Input
f"Max: {result['max']}"
Expected
Max: 9
Test case 3
Input
f"Length: {result['length']}"
Expected
Length: 6
Test case 4
Input
f"Reversed: {result['reversed']}"
Expected
Reversed: [3, 9, 1, 8, 2, 5]
Test case 5
main.py
Hi! I'm Rex 👋
Output
Ready. Press ▶ Run or Ctrl+Enter.