Top 10 Easy DSA Questions for Beginners to Practice

      Top 10 Easy Level DSA Questions to Practice        
   

Top 10 Easy Level DSA Questions to Practice (With Solutions)

   

By Nexus Coder | Updated: July 2025

 
 
   

📌 Why Start with Easy DSA Questions?

   

Whether you're preparing for coding interviews or building your logical thinking, solving easy DSA (Data Structures & Algorithms) problems is a great place to start. These problems help you get comfortable with basic concepts like arrays, strings, loops, and recursion.

 
 
   

🧠 Top 10 Easy DSA Questions for Beginners

   
         
  1.        

    1. Reverse an Array

           

    Problem: Given an array, reverse the elements in-place.

           
    // Input: [1, 2, 3, 4]
    // Output: [4, 3, 2, 1]
           

    DSA Concept: Two-pointer technique.

           
    // C++
    #include <vector>
    #include <algorithm> // For std::reverse
    void reverseArray(std::vector<int>& arr) {
        int left = 0;
        int right = arr.size() - 1;
        while (left < right) {
            std::swap(arr[left], arr[right]);
            left++;
            right--;
        }
    }
    
    // Java
    class Solution {
        public void reverseArray(int[] arr) {
            int left = 0;
            int right = arr.length - 1;
            while (left < right) {
                int temp = arr[left];
                arr[left] = arr[right];
                arr[right] = temp;
                left++;
                right--;
            }
        }
    }
         
  2.      
  3.        

    2. Check Palindrome String

           

    Problem: Determine if a string is a palindrome.

           
    // Input: "madam"
    // Output: true
           

    DSA Concept: String manipulation, pointers.

           
    // C++
    #include <string>
    bool isPalindrome(const std::string& s) {
        int left = 0;
        int right = s.length() - 1;
        while (left < right) {
            if (s[left] != s[right]) {
                return false;
            }
            left++;
            right--;
        }
        return true;
    }
    
    // Java
    class Solution {
        public boolean isPalindrome(String s) {
            int left = 0;
            int right = s.length() - 1;
            while (left < right) {
                if (s.charAt(left) != s.charAt(right)) {
                    return false;
                }
                left++;
                right--;
            }
            return true;
        }
    }
         
  4.      
  5.        

    3. Find Maximum Element in Array

           

    Problem: Return the maximum element from the array.

           
    // Input: [10, 20, 5, 80]
    // Output: 80
           

    DSA Concept: Linear search.

           
    // C++
    #include <vector>
    #include <limits> // For std::numeric_limits
    int findMax(const std::vector<int>& arr) {
        if (arr.empty()) {
            // Handle empty array case, e.g., throw an exception or return a sentinel value
            return std::numeric_limits<int>::min(); // Or throw std::invalid_argument
        }
        int maxElement = arr[0];
        for (size_t i = 1; i < arr.size(); ++i) {
            if (arr[i] > maxElement) {
                maxElement = arr[i];
            }
        }
        return maxElement;
    }
    
    // Java
    class Solution {
        public int findMax(int[] arr) {
            if (arr == null || arr.length == 0) {
                throw new IllegalArgumentException("Array cannot be empty or null");
            }
            int maxElement = arr[0];
            for (int i = 1; i < arr.length; i++) {
                if (arr[i] > maxElement) {
                    maxElement = arr[i];
                }
            }
            return maxElement;
        }
    }
         
  6.      
  7.        

    4. Fibonacci Series (Recursion)

           

    Problem: Print the nth number of the Fibonacci sequence.

           
    // Input: 5
    // Output: 5 (0, 1, 1, 2, 3, 5)
           

    DSA Concept: Recursion.

           
    // C++
    int fibonacci(int n) {
        if (n <= 1) {
            return n;
        }
        return fibonacci(n - 1) + fibonacci(n - 2);
    }
    
    // Java
    class Solution {
        public int fibonacci(int n) {
            if (n <= 1) {
                return n;
            }
            return fibonacci(n - 1) + fibonacci(n - 2);
        }
    }
         
  8.      
  9.        

    5. Count Occurrences of a Character

           

    Problem: Count how many times a character appears in a string.

           
    // Input: "hello", 'l'
    // Output: 2
           

    DSA Concept: Loops, string traversal.

           
    // C++
    #include <string>
    int countCharOccurrences(const std::string& s, char c) {
        int count = 0;
        for (char ch : s) {
            if (ch == c) {
                count++;
            }
        }
        return count;
    }
    
    // Java
    class Solution {
        public int countCharOccurrences(String s, char c) {
            int count = 0;
            for (char ch : s.toCharArray()) {
                if (ch == c) {
                    count++;
                }
            }
            return count;
        }
    }
         
  10.      
  11.        

    6. Linear Search

           

    Problem: Find a number in the array and return its index.

           
    // Input: [3, 8, 1, 7], key = 1
    // Output: 2
           

    DSA Concept: Searching algorithms.

           
    // C++
    #include <vector>
    int linearSearch(const std::vector<int>& arr, int key) {
        for (size_t i = 0; i < arr.size(); ++i) {
            if (arr[i] == key) {
                return i; // Return the index if found
            }
        }
        return -1; // Return -1 if not found
    }
    
    // Java
    class Solution {
        public int linearSearch(int[] arr, int key) {
            for (int i = 0; i < arr.length; i++) {
                if (arr[i] == key) {
                    return i;
                }
            }
            return -1;
        }
    }
         
  12.      
  13.        

    7. Sum of All Elements in an Array

           

    Problem: Calculate the sum of array elements.

           
    // Input: [1, 2, 3, 4]
    // Output: 10
           

    DSA Concept: Loops, array traversal.

           
    // C++
    #include <vector>
    #include <numeric> // For std::accumulate
    long long sumArrayElements(const std::vector<int>& arr) {
        long long sum = 0;
        for (int num : arr) {
            sum += num;
        }
        return sum;
        // return std::accumulate(arr.begin(), arr.end(), 0LL); // More concise
    }
    
    // Java
    class Solution {
        public long sumArrayElements(int[] arr) {
            long sum = 0;
            for (int num : arr) {
                sum += num;
            }
            return sum;
        }
    }
         
  14.      
  15.        

    8. Find the Missing Number

           

    Problem: Find the missing number in a range from 1 to n.

           
    // Input: [1, 2, 4, 5]
    // Output: 3
           

    DSA Concept: Math, summation formula.

           
    // C++
    #include <vector>
    int findMissingNumber(const std::vector<int>& arr, int n) {
        // Sum of numbers from 1 to n: n * (n + 1) / 2
        long long expectedSum = (long long)n * (n + 1) / 2;
        long long actualSum = 0;
        for (int num : arr) {
            actualSum += num;
        }
        return (int)(expectedSum - actualSum);
    }
    
    // Java
    class Solution {
        public int findMissingNumber(int[] arr, int n) {
            long expectedSum = (long)n * (n + 1) / 2;
            long actualSum = 0;
            for (int num : arr) {
                actualSum += num;
            }
            return (int)(expectedSum - actualSum);
        }
    }
         
  16.      
  17.        

    9. Remove Duplicates from Array

           

    Problem: Return array with duplicates removed. (Note: This problem often implies returning the size of the unique elements or modifying in-place for fixed-size arrays.)

           
    // Input: [1, 2, 2, 3, 3]
    // Output: [1, 2, 3]
           

    DSA Concept: Sets, hashing, or two-pointers for sorted arrays.

           
    // C++ (Using std::set for simplicity for unsorted array, or two-pointers for sorted)
    #include <vector>
    #include <set>
    #include <algorithm> // For std::sort, std::unique
    
    // For unsorted array, preserves order if using set + vector, or just using set
    std::vector<int> removeDuplicates(const std::vector<int>& arr) {
        std::set<int> uniqueElements(arr.begin(), arr.end());
        return std::vector<int>(uniqueElements.begin(), uniqueElements.end());
    }
    
    // For sorted array (modifies in-place and returns new size)
    int removeDuplicatesSorted(std::vector<int>& nums) {
        if (nums.empty()) return 0;
        int i = 0; // Pointer for unique elements
        for (int j = 1; j < nums.size(); j++) {
            if (nums[j] != nums[i]) {
                i++;
                nums[i] = nums[j];
            }
        }
        return i + 1; // New length
    }
    
    // Java (Using HashSet for simplicity for unsorted array, or two-pointers for sorted)
    import java.util.ArrayList;
    import java.util.HashSet;
    import java.util.List;
    import java.util.Arrays;
    
    class Solution {
        // For unsorted array, returns a new list
        public List<Integer> removeDuplicates(int[] arr) {
            HashSet<Integer> uniqueElements = new HashSet<>();
            for (int num : arr) {
                uniqueElements.add(num);
            }
            return new ArrayList<>(uniqueElements);
        }
    
        // For sorted array (modifies in-place and returns new length)
        public int removeDuplicatesSorted(int[] nums) {
            if (nums.length == 0) return 0;
            int i = 0; // Pointer for unique elements
            for (int j = 1; j < nums.length; j++) {
                if (nums[j] != nums[i]) {
                    i++;
                    nums[i] = nums[j];
                }
            }
            return i + 1; // New length
        }
    }
         
  18.      
  19.        

    10. Print All Even Numbers

           

    Problem: From 1 to N, print all even numbers.

           
    // Input: 10
    // Output: 2 4 6 8 10
           

    DSA Concept: Loops, conditionals.

           
    // C++
    #include <iostream>
    #include <vector>
    void printEvenNumbers(int n) {
        for (int i = 1; i <= n; ++i) {
            if (i % 2 == 0) {
                std::cout << i << " ";
            }
        }
        std::cout << std::endl;
    }
    
    // Java
    class Solution {
        public void printEvenNumbers(int n) {
            for (int i = 1; i <= n; i++) {
                if (i % 2 == 0) {
                    System.out.print(i + " ");
                }
            }
            System.out.println();
        }
    }
         
  20.    
 
 
   

💡 Final Tips

   
         
  • Practice daily for 30–60 minutes.
  •      
  • Try solving problems on platforms like LeetCode, GeeksforGeeks, and HackerRank.
  •      
  • Understand the logic before jumping to the solution.
  •    
 
 
   

🔗 Read more coding tips on Nexus Coder

   

📌 Tags: DSA, Easy Problems, Beginners, Arrays, Strings, Nexus Coder

 

Post a Comment

Previous Post Next Post