15 Most Repeated Coding Questions in Infosys, TCS & Wipro Interviews
Posted on: Thu Jun 19 2025
✅ The 15 Most Repeated Questions (With Easy-to-Understand Code Snippets)
Each code snippet below is simplified and beginner-friendly. Suitable for students from any background.
1. Two Sum Problem
Problem: Given an array and a target, find two numbers that add up to the target.
Python:
def two_sum(nums, target):
for i in range(len(nums)):
for j in range(i + 1, len(nums)):
if nums[i] + nums[j] == target:
return [i, j]
2. Check Palindrome
Problem: Check if a string is the same forward and backward.
Python:
def is_palindrome(s):
return s == s[::-1]
3. Anagram Check
Problem: Check if two strings have the same letters.
Python:
def is_anagram(s1, s2):
return sorted(s1) == sorted(s2)
4. Remove Duplicates from Array
Python:
def remove_duplicates(arr):
unique = []
for num in arr:
if num not in unique:
unique.append(num)
return unique
5. Fibonacci Series
Python:
def fibonacci(n):
a, b = 0, 1
for _ in range(n):
print(a, end=' ')
a, b = b, a + b
6. Reverse a String
Python:
def reverse_string(s):
return s[::-1]
7. Factorial (Recursion)
Python:
def factorial(n):
if n == 0 or n == 1:
return 1
else:
return n * factorial(n - 1)
8. Missing Number in Array
Python:
def find_missing(arr, n):
expected_sum = n * (n + 1) // 2
actual_sum = sum(arr)
return expected_sum - actual_sum
9. Maximum Occurring Character
Python:
def max_char(s):
freq = {}
for char in s:
freq[char] = freq.get(char, 0) + 1
return max(freq, key=freq.get)
10. Count Vowels and Consonants
Python:
def count_vowels_consonants(s):
vowels = 'aeiouAEIOU'
v = 0
c = 0
for i in s:
if i.isalpha():
if i in vowels:
v += 1
else:
c += 1
return v, c
11. Sort Array of 0s, 1s, 2s
Python:
def sort_zeros_ones_twos(arr):
return sorted(arr)
12. Second Largest Element
Python:
def second_largest(arr):
arr = list(set(arr)) # remove duplicates
arr.sort()
return arr[-2] if len(arr) >= 2 else None
13. Find Duplicates in Array
Python:
def find_duplicates(arr):
seen = set()
duplicates = []
for num in arr:
if num in seen:
if num not in duplicates:
duplicates.append(num)
else:
seen.add(num)
return duplicates
14. Check Prime Number
Python:
def is_prime(n):
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
15. Balanced Parentheses
Python: