Number Pattern Analyzer
Numbers look harmless.
But sequences hide structure.
Order. Repetition. Growth. Collapse. Patterns.
Your job is not to print numbers.
Your job is to observe them precisely.
This project trains:
- Parallel state tracking
- Logical discipline
- Edge-case awareness
- Single-pass reasoning
- Growth intuition
Watch First - How Engineers Observe Patterns
While watching, think about:
- How many times the data is scanned
- What state must be remembered
- Where edge cases appear
- How growth affects performance
Now let’s define the problem clearly.
What You Are Building
Given a list of numbers, your program must:
- Count even numbers
- Count odd numbers
- Find smallest value
- Find largest value
- Detect if strictly increasing
- Detect if strictly decreasing
- Detect duplicates
- Identify first repeated element
No shortcuts.
No external libraries.
Only structured logic.
Think Before Coding
Ask:
- What if the list is empty?
- What if it contains one element?
- What defines “strictly increasing”?
- Can everything be done in one loop?
- What is the time complexity?
- What is the space complexity?
This is where computational thinking begins.
Simple Approach - Multiple Passes
Start simple.
Solve each requirement independently.
def analyze_numbers(numbers):
if not numbers:
return "Empty list"
even_count = sum(1 for n in numbers if n % 2 == 0)
odd_count = sum(1 for n in numbers if n % 2 != 0)
smallest = min(numbers)
largest = max(numbers)
is_increasing = all(numbers[i] < numbers[i + 1] for i in range(len(numbers) - 1))
is_decreasing = all(numbers[i] > numbers[i + 1] for i in range(len(numbers) - 1))
return {
"even": even_count,
"odd": odd_count,
"min": smallest,
"max": largest,
"increasing": is_increasing,
"decreasing": is_decreasing
}
This works.
But notice:
- Multiple passes
- Built-in shortcuts
- Hidden iterations
Time complexity is still O(n), but clarity of state tracking is weaker.
Now we improve it.
Better Approach - Single Pass Structured Thinking
Now we do everything in one loop.
def analyze_numbers(numbers):
if not numbers:
return "Empty list"
even_count = 0
odd_count = 0
smallest = numbers[0]
largest = numbers[0]
is_increasing = True
is_decreasing = True
seen = set()
first_duplicate = None
previous = numbers[0]
for i, n in enumerate(numbers):
# Even / Odd
if n % 2 == 0:
even_count += 1
else:
odd_count += 1
# Min / Max
if n < smallest:
smallest = n
if n > largest:
largest = n
# Duplicate detection
if n in seen and first_duplicate is None:
first_duplicate = n
seen.add(n)
# Order tracking
if i > 0:
if n <= previous:
is_increasing = False
if n >= previous:
is_decreasing = False
previous = n
return {
"even": even_count,
"odd": odd_count,
"min": smallest,
"max": largest,
"increasing": is_increasing,
"decreasing": is_decreasing,
"first_duplicate": first_duplicate
}
Now we:
- Traverse once
- Track multiple states simultaneously
- Maintain order awareness
- Detect duplicates
- Update boundaries
This is disciplined reasoning.
Where Beginners Break
Test with:
[]
[5]
[3, 3, 3]
[1, 2, 3, 4]
[4, 3, 2, 1]
[1, 2, 2, 3]
Ask:
- Should equal elements break increasing?
- Should equal elements break decreasing?
- Is one-element list increasing?
Define your rules clearly.
Ambiguity creates bugs.
Growth Reflection
Time complexity: O(n)
Space complexity: O(n) because of seen.
Can we detect duplicates without extra space?
Yes - by sorting.
But sorting costs O(n log n).
Trade-off:
- Memory vs speed
- Clarity vs performance
This is Big-O intuition becoming practical.
Interview Extension
Enhance analyzer to:
- Detect arithmetic progression
- Detect geometric progression
- Detect alternating pattern
- Return longest increasing streak
- Detect plateau regions
Now it becomes a pattern engine.
Engineering Reflection
Many real systems analyze sequences:
- Stock prices
- Sensor logs
- User behavior
- AI training signals
Pattern detection scales everywhere.
The difference between naive and structured thinking
becomes enormous at scale.
Final Thought
A list of numbers is simple.
But structured observation is not.
If you can track multiple evolving states in one pass,
You are learning to think like an engineer.
