Fresher Technical Interview Preparation
This document contains the most frequently asked coding interview questions for freshers. Each
question is explained step-by-step with logic, followed by Java and Python solutions. At the end of
every question, next-level interview follow-up options are included.
1. Reverse a String
Problem Statement: Reverse a given string.
Step-by-step Logic:
1. Start from the last character of the string.
2. Append each character to a new string.
3. Continue until the first character is reached.
Java Solution:
String s = "hello"; String rev = ""; for(int i = [Link]() - 1; i >= 0; i--) {
rev = rev + [Link](i); } [Link](rev);
Python Solution:
s = "hello" rev = "" for i in range(len(s) - 1, -1, -1): rev += s[i] print(rev)
Next Interview Options:
• Reverse string using recursion
• Reverse string without using extra variable
• Check palindrome using reverse logic
2. Check Palindrome String
Problem Statement: Check whether a string is palindrome.
Step-by-step Logic:
1. Reverse the string.
2. Compare original string with reversed string.
3. If both are equal, it is palindrome.
Java Solution:
String s = "madam"; String rev = new StringBuilder(s).reverse().toString();
if([Link](rev)) { [Link]("Palindrome"); } else {
[Link]("Not Palindrome"); }
Python Solution:
s = "madam" if s == s[::-1]: print("Palindrome") else: print("Not Palindrome")
Next Interview Options:
• Palindrome without using reverse function
• Palindrome for numbers
• Longest palindrome substring
3. Largest Element in Array
Problem Statement: Find the largest number in an array.
Step-by-step Logic:
1. Assume first element is maximum.
2. Compare it with remaining elements.
3. Update maximum when a larger value is found.
Java Solution:
int[] arr = {3, 5, 1, 9}; int max = arr[0]; for(int i = 1; i < [Link]; i++) {
if(arr[i] > max) { max = arr[i]; } } [Link](max);
Python Solution:
arr = [3, 5, 1, 9] max_val = arr[0] for i in arr: if i > max_val: max_val = i
print(max_val)
Next Interview Options:
• Second largest element
• Largest element without sorting
• Largest and smallest in single loop
4. Prime Number Check
Problem Statement: Check if a number is prime.
Step-by-step Logic:
1. Prime number is divisible only by 1 and itself.
2. Check divisibility from 2 to n/2.
3. If divisible, number is not prime.
Java Solution:
int n = 7; boolean isPrime = true; for(int i = 2; i <= n / 2; i++) { if(n % i ==
0) { isPrime = false; break; } } [Link](isPrime);
Python Solution:
n = 7 is_prime = True for i in range(2, n // 2 + 1): if n % i == 0: is_prime =
False break print(is_prime)
Next Interview Options:
• Prime numbers in a range
• Optimized prime check using sqrt(n)
• Count primes in array
5. Fibonacci Series
Problem Statement: Print Fibonacci series.
Step-by-step Logic:
1. Start with 0 and 1.
2. Next number is sum of previous two.
3. Repeat till required count.
Java Solution:
int a = 0, b = 1; for(int i = 0; i < 5; i++) { [Link](a + " "); int c =
a + b; a = b; b = c; }
Python Solution:
a, b = 0, 1 for i in range(5): print(a, end=" ") a, b = b, a + b
Next Interview Options:
• Fibonacci using recursion
• Fibonacci using dynamic programming
• Check if number is Fibonacci
6. Factorial Using Recursion
Problem Statement: Find factorial using recursion.
Step-by-step Logic:
1. Base case: factorial of 1 is 1.
2. Recursive case: n * factorial(n-1).
Java Solution:
int fact(int n) { if(n == 1) { return 1; } return n * fact(n - 1); }
Python Solution:
def fact(n): if n == 1: return 1 return n * fact(n - 1)
Next Interview Options:
• Factorial using loop
• Tail recursion
• Stack overflow explanation
Next-Level Preparation Sections
After completing above basics, prepare the following systematically:
1. Arrays Level-2: Two sum, rotate array, move zeros
2. Strings Level-2: Anagram, longest substring, frequency count
3. Data Structures: Stack, Queue, Linked List
4. OOP Concepts: Inheritance, Polymorphism, Interface vs Abstract
5. SQL Basics: Joins, Group By, Subqueries
6. System Thinking: What happens when you open a website