First and Last Occurrence of Element
📖 Scenario: Imagine you have a list of daily temperatures recorded over a week. You want to find out on which days a specific temperature first and last appeared.
🎯 Goal: You will create a program that finds the first and last positions of a given temperature in the list.
📋 What You'll Learn
Create an array called
temperatures with exact values: [23, 25, 23, 22, 25, 26, 23]Create a variable called
targetTemp and set it to 23Write code to find the first and last occurrence indexes of
targetTemp in temperaturesPrint the first and last occurrence indexes in the format:
First occurrence: X and Last occurrence: Y💡 Why This Matters
🌍 Real World
Finding first and last occurrences helps in analyzing repeated events, like tracking when a temperature first and last appeared in weather data.
💼 Career
This skill is useful in data analysis, debugging logs, and searching through records efficiently.
Progress0 / 4 steps