30 Coding Problems with Solutions for Strong Problem-Solving Skills

Learning programming becomes more effective when concepts are supported by regular problem-solving practice. Reading syntax or understanding theory is useful, but real improvement happens when learners apply those concepts to practical coding problems.

This guide contains 30 coding problems with solutions, beginning with simple programming exercises and gradually moving toward common Data Structures and Algorithms patterns. The problems cover numbers, strings, arrays, searching, sorting, linked lists, stacks, queues, hashing, two pointers, sliding window, and Kadane’s Algorithm.

The progression is useful for students who want to strengthen their programming fundamentals before moving to coding tests and technical interviews.

Why Practicing Coding Problems Matters

Programming is not only about knowing commands or remembering syntax. A learner also needs to understand how to break a problem into smaller steps and convert those steps into working code.

The problems in this guide are arranged in a way that allows learners to move from basic logic to more structured problem-solving.

The early questions focus on simple calculations and conditions. Later sections introduce arrays, searching, sorting, linked lists, stacks, queues, and common interview-oriented problem patterns.

By practicing these problems one by one, learners can become more comfortable with writing logic, using loops and conditions, working with data structures, and understanding how common coding approaches work.

Basic Programming and Number Problems

The first group of problems focuses on building programming logic through numbers and basic operations.

Find the Largest and Smallest Element in an Array

The first problem works with an array of numbers and finds both the largest and smallest values.

The solution starts by assigning the first array element as both the initial largest and smallest value. It then checks every number in the array and updates the values when required.

This problem is a simple introduction to array traversal and comparison logic.

Check Whether a Number Is Prime

The prime-number problem checks whether a given number has any divisor other than 1 and itself.

In the provided solution, the program first handles numbers below 2 and then checks possible divisors up to the square root of the number. If a divisor is found, the number is treated as not prime.

This exercise helps learners practice loops, conditions, and divisibility checks.

Check Whether a Number Is a Palindrome

A palindrome number remains the same when its digits are reversed.

The guide demonstrates this using the number 121. The original value is stored, the number is reversed digit by digit, and the reversed result is compared with the original number.

This is a useful exercise for understanding loops and arithmetic operations on digits.

Check Whether a Number Is an Armstrong Number

The Armstrong-number problem uses 153 as the example.

The number is converted into digits, the number of digits is calculated, and each digit is raised to that power. The values are then added together and compared with the original number.

This problem introduces learners to digit processing and repeated calculations.

Find the Factorial of a Number

The factorial problem starts with the value 5 and repeatedly multiplies numbers from 1 through the given value.

It is a straightforward example of using a loop to build a cumulative result.

Generate the Fibonacci Series

The Fibonacci problem generates a sequence using two starting values, 0 and 1.

After printing the current value, the solution updates the pair so that each new number is created from the previous two values.

This problem helps learners understand variable updates and sequence generation.

Number, String, and Counting Problems

After the initial number problems, the guide moves into exercises that involve number manipulation and string handling.

Find the GCD and LCM of Two Numbers

The guide uses 12 and 18 as sample values.

The Greatest Common Divisor is calculated using repeated remainder operations. Once the GCD is available, the Least Common Multiple is calculated using the relationship between the two input numbers and the GCD.

Reverse a Number and a String

The document demonstrates two forms of reversal.

For the number 12345, each digit is extracted and used to build the reversed value.

For the string “Python”, characters are processed one by one and added in reverse order.

These exercises help learners understand how similar goals can require different approaches depending on the type of data.

Count Digits, Vowels, and Consonants

The guide includes separate examples for counting digits and for counting vowels and consonants.

For digit counting, each character in "Hello123" is checked to determine whether it is numeric.

For vowels and consonants, "Hello World" is converted to lowercase, alphabetic characters are identified, and each character is classified as either a vowel or consonant.

These problems are useful for practicing string traversal and character-level conditions.

Array-Based Coding Problems

Arrays are an important part of the guide. Several problems focus on reading, modifying, and analyzing collections of values.

Find the Sum and Average of Array Elements

The guide uses the array [10, 20, 30, 40, 50].

Each element is added to a running total, and the average is calculated by dividing the total by the number of elements.

Find the Second Largest Distinct Element

The solution keeps track of both the largest and second-largest values.

As each number is processed, these values are updated when a larger distinct value is found. The solution also checks whether a valid second-largest value exists.

Remove Duplicate Elements from an Array

The duplicate-removal problem uses the array:

[1, 2, 2, 3, 4, 4, 5]

A new result list is created, and each value is added only if it is not already present.

Find the Missing Number from 1 to N

The sample array is:

[1, 2, 3, 5, 6]

The expected sum from 1 through N is calculated and compared with the actual sum of the array. The difference gives the missing number.

Move All Zeros to the End

The guide demonstrates this using:

[0, 1, 0, 3, 12]

Non-zero values are moved forward first, after which the remaining positions are filled with zeros.

Find the Frequency of Each Element

A dictionary is used to count how many times every element appears in the array.

For each number, the existing count is retrieved and increased by one.

Find a Pair With a Given Sum

The sample array is [2, 7, 11, 15] with a target value of 9.

The solution stores previously seen numbers and checks whether the required complement for the current number has already appeared.

These array problems gradually introduce learners to common coding patterns such as scanning, filtering, counting, and lookup.

Searching and Sorting Problems

Searching and sorting form another important part of the guide.

Linear Search

Linear search checks each element one by one until the target value is found.

In the provided example, the array contains[10, 20, 30, 40, 50], and the program searches for 30.

Binary Search

Binary search is demonstrated using a sorted array.

The solution keeps left and right boundaries, calculates the middle position, and repeatedly reduces the search range based on whether the target is greater or smaller than the middle element.

The guide specifically notes that the array must be sorted before binary search is used.

Bubble Sort

Bubble sort repeatedly compares neighboring elements and swaps them when they are in the wrong order.

The process continues until the array becomes sorted.

Selection Sort

Selection sort searches for the smallest element in the remaining unsorted portion and places it in the correct position.

Insertion Sort

Insertion sort takes each new element and moves it backward through the already processed section until it reaches the correct position.

Together, these exercises give learners practical exposure to multiple approaches for searching and arranging data.

String and Two-Pointer Problems

The next section introduces problems that require more structured string processing.

Check String Palindrome Using Two Pointers

The sample word is "madam".

One pointer starts from the beginning of the string and another starts from the end. The characters are compared while both pointers move toward the center.

This introduces the two-pointer approach in a simple way.

Find the First Non-Repeating Character

The guide uses "swiss" as the sample string.

First, the frequency of each character is counted. The string is then checked again to identify the first character whose frequency is one.

This problem combines string traversal with frequency counting.

Linked List Problems

The guide then moves from arrays and strings to linked lists.

Reverse a Singly Linked List

A small linked list containing the values 1, 2, and 3 is created.

The solution uses previous, current, and next references to change the direction of the links one node at a time.

Detect a Cycle in a Linked List

The cycle-detection problem uses two pointers named slow and fast.

The slow pointer advances one step, while the fast pointer advances two steps. If both pointers meet, the solution identifies that a cycle exists.

Find the Middle Element of a Linked List

The guide again uses slow and fast pointers.

The fast pointer moves twice as quickly as the slow pointer. When the fast pointer reaches the end, the slow pointer indicates the middle element.

The document also notes that for an even-length list, this approach returns the second middle element.

Stack and Queue Problems

Stacks and queues are introduced through simple practical examples.

Check for Balanced Parentheses Using a Stack

The sample input is:

{[()]}

Opening brackets are pushed onto a stack. When a closing bracket appears, the solution checks whether it matches the expected opening bracket.

Implement a Stack Using an Array

The guide demonstrates basic stack operations using a list.

Values are added with append operations, and the most recently added item is removed using pop().

Implement a Queue Using an Array

The queue example uses deque.

Values are added at the end, while removal takes place from the front using popleft().

These examples help learners understand the practical behavior of stack and queue operations.

Common Coding Interview Patterns

The final problems in the PDF introduce several patterns commonly practiced for coding assessments.

Find the Unique Intersection of Two Arrays

The guide compares two arrays and uses sets to identify values that appear in both arrays.

The result contains only unique common values.

Find the Maximum Subarray Sum Using Kadane’s Algorithm

The sample array contains both positive and negative values.

The solution keeps track of a current sum and a maximum sum. For every new value, it decides whether to start a new subarray or continue the current one.

Find the Longest Substring Without Repeating Characters

The guide uses the string "abcabcbb".

A set stores characters currently in the window. When a repeated character appears, the left side of the window moves forward until the repetition is removed.

Two Sum Using Hashing

The final problem again uses the array [2, 7, 11, 15] with target 9.

A dictionary stores previously visited values and their indices. For every number, the solution checks whether its required complement already exists.

Recommended Learning Order

The PDF provides a clear progression for learners.

1st Year

Basic Programming → Logic → Numbers → Strings → Arrays

At this stage, the focus is on developing programming fundamentals and becoming comfortable with basic problem-solving.

2nd Year

Arrays → Searching → Sorting → Hashing → Two Pointers

The next stage introduces more structured techniques for working with data and solving common coding problems.

3rd Year

Linked Lists → Stack → Queue → Sliding Window → Kadane’s Algorithm → Hashing

The final stage moves into frequently used DSA patterns and more interview-oriented problems.

The stated goal of this progression is to build strong problem-solving fundamentals first and then gradually move toward common DSA patterns used in coding tests and technical interviews.

Who Can Benefit From This Guide?

Based on the learning progression in the PDF, this collection can help learners build programming fundamentals and gradually prepare for more structured DSA practice.

It can support:

Because the problems move from simple number logic to arrays, searching, sorting, linked lists, stacks, queues, and common patterns, the guide can be followed progressively rather than randomly.

Conclusion

Strong problem-solving skills are built through regular practice.

The 30 coding problems with solutions in this guide provide a clear progression from basic programming exercises to commonly used DSA patterns. Learners begin with numbers, strings, and arrays before moving into searching, sorting, hashing, linked lists, stacks, queues, two pointers, sliding window, and Kadane’s Algorithm.

Free Resources