Sitemap
Harsh Jaiswal

Harsh Jaiswal

B.Tech CSE | DSA & C/C++ Enthusiast | Web Dev Learner | GATE Aspirant Blogging my tech journey | Future startup founder | Lifelong learner

Array : Traversal & Basic Operations

5 min readJun 5, 2026

--

When I started revising Arrays, I realized that many interview questions are built on a few fundamental concepts. Before jumping into advanced patterns like Two Pointers, Sliding Window, or Binary Search, it is important to master the basics.

In this phase of my DSA journey, I focused on the Traversal & Basic Operations pattern and solved several related LeetCode problems.

Topics Covered

  • Find Maximum Element
  • Find Minimum Element
  • Check if an Array is Sorted
  • Count Frequency of Elements
  • Remove Duplicates from Sorted Array

These problems may look simple, but they help build the thinking process required for solving more complex array questions.

The Core Idea

After solving multiple problems, I found one common observation:

Most basic array problems can be solved by traversing the array once while maintaining some state (maximum value, count, frequency, index, etc.).

The general approach looks like this:

  1. Traverse the array.
  2. Compare the current element with previously stored information.
  3. Update the required state.
  4. Continue until the end of the array.

This simple pattern appears repeatedly in interviews.

Problem 1: Find Maximum / Minimum Element

“Keep the first element as the current answer and continuously update it whenever a better candidate is found during traversal.”

The goal is to keep track of the current maximum or minimum while traversing the array.

Imagine a class monitor selection.

You enter a classroom and initially assume the first student is the tallest.

Now you start checking every other student:

  • If a student is taller than the current tallest, make them the new tallest.
  • Otherwise, keep the current tallest.

By the time you’ve checked everyone, you’ll know the tallest student in the class.

Press enter or click to view image in full size
Press enter or click to view image in full size
Press enter or click to view image in full size
Press enter or click to view image in full size
Press enter or click to view image in full size

Key Learning: Always think about whether the answer can be updated during traversal instead of storing extra information.

Problem 2: Check if Array is Sorted

A simple but important interview question.

Imagine you’re standing in a queue and everyone’s height should be non-decreasing from left to right.

As you move through the queue, you compare each person with the next person.

  • If the next person is taller or equal, everything is fine.
  • If the next person is shorter, the queue is no longer sorted.

This is exactly how we check whether an array is sorted.

We compare adjacent elements and verify whether the sorted property is maintained throughout the traversal.

Press enter or click to view image in full size
Press enter or click to view image in full size

Key Learning: Many validation problems can be solved by checking relationships between neighboring elements.

Problem 3: Count Frequency of Elements

Frequency-based problems introduce the concept of hashing.

Using a hash map allows us to count occurrences efficiently.

Get Harsh Jaiswal’s stories in your inbox

Join Medium for free to get updates from this writer.

Imagine you’re a teacher taking attendance.

As each student enters the classroom, you maintain a register:

Rahul → 1
Aman → 1
Rahul → 2
Priya → 1
Rahul → 3

Every time you see a student again, you increase their count.

This is exactly what frequency counting does in an array.

Press enter or click to view image in full size
Press enter or click to view image in full size

Key Learning: Whenever a problem asks “how many times does something occur?”, hashing should be one of the first approaches to consider.

Problem 4: Remove Duplicates

This problem introduces the Two Pointer technique in a simple form.

Instead of creating a new array, we modify the existing array efficiently.

Imagine you’re arranging students in a line for a group photo.

A A B B B C C D

You only want one student of each name to stand in the front part of the line.

So you keep:

  • A ✅
  • Skip second A ❌
  • B ✅
  • Skip remaining B’s ❌
  • C ✅
  • Skip second C ❌
  • D ✅

Final unique section:

A B C D

Press enter or click to view image in full size
Press enter or click to view image in full size
Press enter or click to view image in full size

Key Learning: Sorted arrays often unlock more optimized solutions.

Common Observations

After completing these problems, I noticed several recurring patterns:

  • Most optimal solutions run in O(n) time.
  • Traversal is the foundation of almost every array problem.
  • Maintaining state is more important than storing all information.
  • Hashing is useful for frequency-related questions.
  • Sorted arrays often suggest Two Pointers or Binary Search.
  • Edge cases (duplicates, single element arrays, negative values) are crucial.

What’s Next?

With these fundamentals covered, I am moving toward more array patterns such as:

  • Two Pointers
  • Sliding Window
  • Prefix Sum
  • Binary Search on Arrays

Building strong fundamentals first makes advanced topics much easier to understand.

Thanks for reading!

If you’re also learning DSA, feel free to connect and share your progress. Consistency in solving problems is what creates long-term improvement.

👋 Connect with Me:
🔎LEETCODE :-
https://leetcode.com/u/HARSHJAISWAL052723/

👤LinkedIn :- https://www.linkedin.com/in/mr-harsh-jaiswal-76691a32a/

Written by Mr. Harsh Jaiswal — B.Tech CSE | DSA & Web Development

#Array #Traversal&Basic Operations #DSA #CodingInterview #EnjoyProblems

--

--

Written by Harsh Jaiswal

B.Tech CSE | DSA & C/C++ Enthusiast | Web Dev Learner | GATE Aspirant Blogging my tech journey | Future startup founder | Lifelong learner