TARGETROOT
ToolsBlogPracticeInterview
PROGRAMMING TOPICS
Core Java Interview MCQsJavaScript FundamentalsPython Programming MCQsReact & System DesignAll Programming TopicsView All Practice
HomePracticeProgrammingGeneral Coding Problems

General Coding Problems Questions

TARGETROOT

Learning and practice platform built for focused growth. Start lean with tools, blog content, interview prep, and JSON-driven tests.

Platform

  • Tools
  • Blog
  • Practice
  • Interview

Learn

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Service

Quick Access

  • JSON Formatter
  • Image Compressor
  • JSON to XLSX
  • QR Code Generator

© 2026 TARGETROOT. All rights reserved.

Made for focused learners worldwide

Coding Practice
40 coding problems. Review solutions and explanations below each problem.
Question 1

Write a program to count vowels and consonants in a string.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Iterate through characters, check alphabets, and count vowels separately from consonants.
Question 2

Move all zeroes in an array to the end while maintaining the order of non-zero elements.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Use a write pointer for non-zero elements, then fill the remaining positions with zeroes.
Question 3

Write a program to find the missing number in an array of size n-1 containing numbers from 1 to n.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Calculate the sum of first n natural numbers (n*(n+1)/2) and subtract the sum of array elements.
Question 4

Write a program to check if a string is a palindrome (ignoring spaces, punctuation, and case).

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Use two pointers from start and end, skip non-alphanumeric characters, and compare characters case-insensitively.
Question 5

Write a program to find all pairs in an integer array whose sum equals a given target value.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Use a hash set to store visited numbers. For each element, check if (target - element) exists in the set.
Question 6

Write a program to merge two sorted arrays into a single sorted array.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Use two pointers to compare elements from both arrays and place the smaller one into the result array.
Question 7

Write a program to check whether a string is a palindrome.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Compare characters from both ends and move toward the center. If all pairs match, the string is a palindrome.
Question 8

Find the sum of even numbers in an array.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Iterate through the array, check each element with modulo 2, and add only even values to a sum variable.
Question 9

Check whether a number is prime.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Check divisibility from 2 to the square root of the number. If no divisor is found, it is prime.
Question 10

Write a program to reverse a given string.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Iterate the string from the last character to the first, appending each character to build the reversed string.
Question 11

Write a program to find the factorial of a given number.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Use a loop multiplying numbers from 1 to N, or use recursion with base case N=0 returning 1.
Question 12

Write a program to count the number of vowels in a given string.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Traverse the string and check each character against the vowels (a, e, i, o, u) both lowercase and uppercase, incrementing a counter.
Question 13

Write a program to find the second largest number in an array.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Track largest and second largest values in one pass. Update second largest whenever a value is less than largest but greater than current second largest.
Question 14

Check whether two strings are anagrams of each other.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Compare character frequencies using a map, or sort both strings and compare the sorted results.
Question 15

Find the factorial of a number using recursion.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Use base case n <= 1 returns 1, otherwise return n multiplied by factorial(n - 1).
Question 16

Write a program to reverse an array without using extra space.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Use two pointers, one at start and one at end, and swap elements while moving towards the centre.
Question 17

Write a program to count the number of vowels and consonants in a given string.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Traverse the string and increment vowel count for a, e, i, o, u and consonant count for the remaining alphabets.
Question 18

Write a program to check if a number is prime.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
A number is prime if it is greater than 1 and has no divisors other than 1 and itself. Check divisibility up to sqrt(n).
Question 19

Write a recursive function to compute the nth Fibonacci number.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Use base cases fib(0) = 0 and fib(1) = 1. For n > 1, return fib(n-1) + fib(n-2).
Question 20

Write a program to find the first non-repeating character in a string.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Use a hash map to count character frequencies, then traverse the string again to find the first character with count 1.
Question 21

Write a program to merge two sorted arrays into one sorted array.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Use two pointers to compare elements from both arrays and insert the smaller one into the result array.
Question 22

Write a program to print a pyramid pattern of stars with n rows.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Use nested loops: outer loop for rows, inner loops for spaces and stars. Number of stars in row i is 2*i - 1.
Question 23

Write a program to reverse a string without using built-in functions.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Use a two-pointer approach or iterate from end to start swapping characters.
Question 24

Find the second largest element in an array.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Track the largest and second largest in one pass through the array.
Question 25

Check if a given string is a palindrome.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Compare characters from both ends moving toward the center.
Question 26

Print the Fibonacci series up to N terms.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Use iterative approach: start with 0, 1 and keep adding the last two numbers.
Question 27

Count the frequency of each character in a string.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Use a hash map / object to store character counts.
Question 28

Find if two strings are anagrams of each other.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Sort both strings and compare, or count character frequencies.
Question 29

Remove duplicate characters from a string.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Use a Set to track seen characters and build a result string.
Question 30

Check if a number is prime.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Check divisibility from 2 to sqrt(n). If any divides, it's not prime.
Question 31

Find the sum of all elements in an array.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Iterate through the array and accumulate the sum in a variable.
Question 32

Find the missing number in an array containing n-1 integers from 1 to n.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Calculate expected sum = n(n+1)/2 and subtract actual sum to find the missing number.
Question 33

Print a pyramid pattern of stars with N rows.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
For each row i, print (N-i) spaces and (2i-1) stars. Use nested loops.
Question 34

Write a program to print the Fibonacci series up to N terms.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Start with 0 and 1, then repeatedly print the sum of the previous two numbers.
Question 35

Reverse a string without using a built-in reverse function.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Loop from the last character to the first and append each character to a result string, or use two pointers.
Question 36

Find the largest element in an array.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Initialize max with the first element and compare every next element to update the maximum.
Question 37

Write a program to check if a given number is prime.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
A prime number is greater than 1 and divisible only by 1 and itself. Check divisibility from 2 to √n.
Question 38

Write a program to check if a given string is a palindrome.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
A palindrome reads the same forwards and backwards. Reverse the string and compare with the original.
Question 39

Write a program to calculate the factorial of a number N.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Factorial of N is N × (N-1) × (N-2) × ... × 1. Use a loop or recursion.
Question 40

Write a program to find the sum of digits of a given number.

Solve this coding problem in your preferred language. Review the solution below once you're done.
Solution
Extract digits using modulo 10, add to sum, divide by 10. Repeat until the number becomes 0.