First and Last Occurrence of Element
📖 Scenario: You have a list of numbers representing daily temperatures recorded over several days. You want to find the first and last day a specific temperature was recorded.
🎯 Goal: Build a program that finds the first and last position of a given temperature in the list.
📋 What You'll Learn
Create a vector called
temperatures with the exact values: 23, 25, 23, 22, 25, 23, 24Create an integer variable called
target and set it to 23Write a loop to find the first occurrence index of
target in temperaturesWrite a loop to find the last occurrence index of
target in temperaturesPrint the first and last occurrence indices separated by a space
💡 Why This Matters
🌍 Real World
Finding the first and last occurrence of an element is useful in analyzing time series data, logs, or any ordered data to know when an event started and ended.
💼 Career
This skill is important for software developers and data analysts who work with arrays or lists and need to locate specific data points efficiently.
Progress0 / 4 steps