Latest Coding Questions Asked to Freshers: Complete Guide with Solutions
The job market for fresh engineers is more competitive than ever. With companies like Microsoft, Google, Amazon, and emerging startups actively hiring, coding interviews have become the primary filter for technical roles. This comprehensive guide covers the most frequently asked coding questions in 2025, complete with detailed solutions and explanations.
Why Coding Questions Matter for Freshers
Coding questions serve as the foundation for technical interviews, regardless of whether you’re applying to product-based companies or service-based organizations. Recent industry analysis shows that over 90% of software engineering roles require candidates to solve coding problems during the interview process.
Current Hiring Trends (2025)
- High emphasis on problem-solving skills over theoretical knowledge
- Live coding sessions becoming more common than take-home assignments
- Data Structures and Algorithms remain the core focus
- Time complexity analysis is expected for most solutions
- Multiple programming languages accepted (Python, Java, C++, JavaScript)
Most Asked Coding Questions by Category
1. Basic Programming Fundamentals
These questions test your understanding of core programming concepts and are typically asked in the first round of technical interviews.
Question 1: How do you reverse a string?
Difficulty: Easy | Frequency: Very High | Companies: Google, Microsoft, Amazon
Problem Statement: Given a string, return its reverse without using built-in reverse functions.
Python Solution:
def reverse_string(s):
# Method 1: Using slicing (most Pythonic)
return s[::-1]
# Method 2: Using two pointers
def reverse_string_two_pointer(s):
chars = list(s)
left, right = 0, len(chars) - 1
while left < right:
chars[left], chars[right] = chars[right], chars[left]
left += 1
right -= 1
return ''.join(chars)
# Method 3: Using recursion
def reverse_string_recursive(s):
if len(s) <= 1:
return s
return s[-1] + reverse_string_recursive(s[:-1])
# Example usage
print(reverse_string("Hello World")) # Output: "dlroW olleH"
Java Solution:
public class ReverseString {
// Method 1: Using StringBuilder
public static String reverseString(String s) {
return new StringBuilder(s).reverse().toString();
}
// Method 2: Using character array
public static String reverseStringArray(String s) {
char[] chars = s.toCharArray();
int left = 0, right = chars.length - 1;
while (left < right) {
char temp = chars[left];
chars[left] = chars[right];
chars[right] = temp;
left++;
right--;
}
return new String(chars);
}
// Method 3: Using recursion
public static String reverseStringRecursive(String s) {
if (s.length() <= 1) return s;
return s.charAt(s.length() - 1) +
reverseStringRecursive(s.substring(0, s.length() - 1));
}
}
Time Complexity: O(n) | Space Complexity: O(1) for two-pointer approach
Key Points for Interview:
- Discuss multiple approaches
- Mention time and space complexity
- Handle edge cases (empty string, single character)
- Be ready to implement without built-in functions
Question 2: Check if a number is prime
Difficulty: Easy | Frequency: High | Companies: TCS, Infosys, Wipro
Problem Statement: Determine if a given number is prime (only divisible by 1 and itself).
Python Solution:
def is_prime(n):
# Handle edge cases
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
# Check for divisors from 5 to sqrt(n)
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
# Example usage
print(is_prime(17)) # Output: True
print(is_prime(4)) # Output: False
print(is_prime(29)) # Output: True
Java Solution:
public class PrimeChecker {
public static boolean isPrime(int n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i += 6) {
if (n % i == 0 || n % (i + 2) == 0) {
return false;
}
}
return true;
}
// Simple approach for beginners
public static boolean isPrimeSimple(int n) {
if (n <= 1) return false;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) return false;
}
return true;
}
}
Time Complexity: O(√n) | Space Complexity: O(1)
Interview Tips:
- Start with simple O(n) approach, then optimize to O(√n)
- Explain the 6k±1 optimization if asked
- Handle edge cases (negative numbers, 0, 1)
Question 3: Calculate factorial of a number
Difficulty: Easy | Frequency: Very High | Companies: Accenture, Cognizant, HCL
Problem Statement: Calculate n! (factorial) using both iterative and recursive approaches.
Python Solution:
# Recursive approach
def factorial_recursive(n):
if n <= 1:
return 1
return n * factorial_recursive(n - 1)
# Iterative approach
def factorial_iterative(n):
if n <= 1:
return 1
result = 1
for i in range(2, n + 1):
result *= i
return result
# Example usage
print(factorial_recursive(5)) # Output: 120
print(factorial_iterative(0)) # Output: 1
Java Solution:
public class Factorial {
// Recursive approach
public static long factorialRecursive(int n) {
if (n <= 1) return 1;
return n * factorialRecursive(n - 1);
}
// Iterative approach
public static long factorialIterative(int n) {
if (n <= 1) return 1;
long result = 1;
for (int i = 2; i <= n; i++) {
result *= i;
}
return result;
}
}
Time Complexity: O(n) | Space Complexity: O(1) for iterative, O(n) for recursive
2. Arrays and Strings
Array and string manipulation questions are among the most frequently asked in coding interviews, especially for freshers.
Question 4: Find the maximum element in an array
Difficulty: Easy | Frequency: Very High | Companies: All major companies
Problem Statement: Find the largest element in an unsorted array.
Python Solution:
def find_max(arr):
if not arr:
return None # or raise an exception
max_val = arr[0]
for i in range(1, len(arr)):
if arr[i] > max_val:
max_val = arr[i]
return max_val
# Example usage
nums = [3, 7, 1, 9, 2, 8, 5]
print(find_max(nums)) # Output: 9
Java Solution:
public class FindMaximum {
public static int findMax(int[] arr) {
if (arr.length == 0) {
throw new IllegalArgumentException("Array is empty");
}
int max = arr[0];
for (int i = 1; i < arr.length; i++) {
if (arr[i] > max) {
max = arr[i];
}
}
return max;
}
}
Time Complexity: O(n) | Space Complexity: O(1)
Question 5: Check if a string is a palindrome
Difficulty: Easy | Frequency: High | Companies: Google, Facebook, Amazon
Problem Statement: Determine if a string reads the same forwards and backwards.
Python Solution:
def is_palindrome(s):
# Simple approach
s = s.lower().replace(' ', '')
return s == s[::-1]
# Two-pointer approach
def is_palindrome_two_pointer(s):
# Clean the string
cleaned = ''.join(char.lower() for char in s if char.isalnum())
left, right = 0, len(cleaned) - 1
while left < right:
if cleaned[left] != cleaned[right]:
return False
left += 1
right -= 1
return True
# Example usage
print(is_palindrome("racecar")) # Output: True
print(is_palindrome("A man a plan a canal Panama")) # Output: True
print(is_palindrome("hello")) # Output: False
Java Solution:
public class PalindromeChecker {
public static boolean isPalindrome(String s) {
// Clean the string
String cleaned = s.replaceAll("[^a-zA-Z0-9]", "").toLowerCase();
int left = 0, right = cleaned.length() - 1;
while (left < right) {
if (cleaned.charAt(left) != cleaned.charAt(right)) {
return false;
}
left++;
right--;
}
return true;
}
}
Time Complexity: O(n) | Space Complexity: O(1) for two-pointer approach
3. Data Structures Implementation
Understanding how to implement basic data structures is crucial for demonstrating your computer science fundamentals.
Question 6: Implement a Stack using arrays
Difficulty: Medium | Frequency: High | Companies: Amazon, Microsoft, Google
Problem Statement: Implement a stack data structure with push, pop, peek, and isEmpty operations.
Python Solution:
class Stack:
def __init__(self, max_size=100):
self.items = []
self.max_size = max_size
def push(self, item):
if len(self.items) >= self.max_size:
raise Exception("Stack Overflow")
self.items.append(item)
def pop(self):
if self.is_empty():
raise Exception("Stack Underflow")
return self.items.pop()
def peek(self):
if self.is_empty():
raise Exception("Stack is empty")
return self.items[-1]
def is_empty(self):
return len(self.items) == 0
def size(self):
return len(self.items)
# Example usage
stack = Stack()
stack.push(10)
stack.push(20)
stack.push(30)
print(stack.peek()) # Output: 30
print(stack.pop()) # Output: 30
Java Solution:
public class Stack {
private int[] items;
private int top;
private int maxSize;
public Stack(int maxSize) {
this.maxSize = maxSize;
this.items = new int[maxSize];
this.top = -1;
}
public void push(int item) {
if (top >= maxSize - 1) {
throw new RuntimeException("Stack Overflow");
}
items[++top] = item;
}
public int pop() {
if (isEmpty()) {
throw new RuntimeException("Stack Underflow");
}
return items[top--];
}
public int peek() {
if (isEmpty()) {
throw new RuntimeException("Stack is empty");
}
return items[top];
}
public boolean isEmpty() {
return top == -1;
}
public int size() {
return top + 1;
}
}
Time Complexity: O(1) for all operations | Space Complexity: O(n) where n is the maximum size
4. Mathematical and Logical Problems
These problems test your mathematical reasoning and logical thinking abilities.
Question 7: Generate Fibonacci series
Difficulty: Easy | Frequency: Very High | Companies: All major companies
Problem Statement: Generate the first n numbers in the Fibonacci sequence.
Python Solution:
def fibonacci_series(n):
if n <= 0:
return []
elif n == 1:
return [0]
elif n == 2:
return [0, 1]
fib = [0, 1]
for i in range(2, n):
fib.append(fib[i-1] + fib[i-2])
return fib
# Recursive approach
def fibonacci_recursive(n):
if n <= 1:
return n
return fibonacci_recursive(n-1) + fibonacci_recursive(n-2)
# Example usage
print(fibonacci_series(10)) # Output: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
Java Solution:
public class Fibonacci {
// Iterative approach
public static int[] fibonacciSeries(int n) {
if (n <= 0) return new int[0];
if (n == 1) return new int[]{0};
if (n == 2) return new int[]{0, 1};
int[] fib = new int[n];
fib[0] = 0;
fib[1] = 1;
for (int i = 2; i < n; i++) {
fib[i] = fib[i-1] + fib[i-2];
}
return fib;
}
// Recursive approach
public static int fibonacciRecursive(int n) {
if (n <= 1) return n;
return fibonacciRecursive(n-1) + fibonacciRecursive(n-2);
}
}
Time Complexity: O(n) iterative, O(2^n) recursive | Space Complexity: O(n) for storing sequence
Major Companies Hiring Fresh Engineers
Tier 1 Companies
Company | Role | Application Status |
---|---|---|
Microsoft | Software Engineer Intern | Open |
Software Developer | Open | |
Amazon | SDE-I | Open |
Apple | Software Engineer | Open |
Meta | Software Engineer | Open |
Tier 2 Product Companies
Company | Role | Application Status |
---|---|---|
Flipkart | Software Engineer | Open |
Swiggy | Backend Developer | Open |
Zomato | Full Stack Developer | Open |
Paytm | Software Developer | Open |
PhonePe | Software Engineer | Open |
Application Tips for Fresh Engineers
1. Resume Optimization
- Keep it concise - Maximum 2 pages
- Highlight projects - Include personal and academic projects
- Technical skills section - List programming languages and tools
- Quantify achievements - Use numbers and metrics where possible
2. Technical Preparation
- Data Structures & Algorithms - Practice coding problems daily
- System Design basics - Understand scalability concepts
- Project portfolio - Build 2-3 substantial projects
- Code repositories - Maintain clean, documented code
3. Interview Preparation
- Technical rounds - Practice coding on whiteboard/online platforms
- Behavioral questions - Prepare STAR method responses
- Company research - Know the company's products and culture
- Mock interviews - Practice with peers or mentors
Best Practices for Interview Success
Technical Skills in High Demand
- Cloud platforms (AWS, Azure, GCP)
- Containerization (Docker, Kubernetes)
- Machine Learning and AI basics
- Mobile development (React Native, Flutter)
- Cybersecurity fundamentals
Soft Skills Employers Value
- Communication skills - Ability to explain technical concepts
- Problem-solving - Analytical thinking approach
- Team collaboration - Working effectively in groups
- Adaptability - Learning new technologies quickly
- Leadership potential - Taking initiative in projects
Action Steps to Get Started
Immediate Actions (This Week)
- Update your resume with latest projects and skills
- Create professional profiles and connect with professionals
- Start coding practice - Solve 2-3 problems daily
- Apply to 5-10 companies that match your profile
Medium-term Goals (Next Month)
- Complete 2-3 technical projects for your portfolio
- Participate in hackathons or coding competitions
- Network with professionals in your field
- Practice mock interviews with peers
Long-term Strategy (Next 3 Months)
- Continuously learn new technologies
- Build professional network through events and online communities
- Contribute to open source projects
- Seek mentorship from senior engineers
Common Mistakes to Avoid
Technical Mistakes
- Not handling edge cases (null, empty arrays)
- Integer overflow in mathematical calculations
- Off-by-one errors in loops and array indexing
- Not initializing variables properly
- Forgetting to return values from functions
Interview Mistakes
- Jumping to code without understanding the problem
- Not asking clarifying questions
- Silent coding without explaining the approach
- Giving up too quickly when stuck
- Not testing the solution with examples
Conclusion
Success in coding interviews requires consistent practice, strong fundamentals, and effective problem-solving strategies. The questions covered in this guide represent the most frequently asked problems in 2025 interviews across various companies and difficulty levels.
Remember that coding interviews are not just about getting the right answer – they're about demonstrating your thought process, communication skills, and ability to work under pressure. Practice regularly, stay updated with current trends, and approach each problem with confidence and clarity.
Key Takeaways:
- Master the fundamentals before moving to advanced topics
- Practice explaining your solutions clearly
- Handle edge cases and optimize your code
- Stay calm and think step-by-step during interviews
- Learn from your mistakes and keep improving
The coding interview landscape continues to evolve, but these fundamental problems and problem-solving techniques remain the cornerstone of technical assessment. With dedicated practice and the right approach, you'll be well-prepared to tackle any coding challenge that comes your way.
Ready to start your coding interview preparation? Begin with the basic problems and gradually work your way up to more complex challenges. Remember, every expert was once a beginner – stay consistent, stay motivated, and success will follow.
Apply Now: Visit our job listings to find the perfect engineering role for you!