1.
Number-Based Problems:
• Check for Leap Year: Write a program to determine if a given year is a leap year.
• Prime Numbers: Check if a number is prime.
• Armstrong Numbers: Check if a given number is an Armstrong number.
• Perfect Number: Identify if a number is a perfect number.
• Fibonacci Series: Generate the Fibonacci series up to n terms.
• Sum of First n Natural Numbers: Compute the sum of the first n natural numbers.
• Add Digits: Given a number, find the sum of its digits.
• Replace all '0's with '5' in a number.
2. Array-Based Problems:
• Find Duplicates: Identify duplicates in an array in O(n) time and O(1) space.
• Array Rotation: Rotate an array K times to the right.
• Sum of Array Elements: Find the sum of all elements in an array.
• Find the Third Maximum Number: Given an array, find the third largest element.
• Sorting Arrays: Implement sorting algorithms such as Bubble Sort, Insertion Sort, Selection Sort.
• Pascal's Triangle: Print Pascal's Triangle up to n rows.
3. String-Based Problems:
• Palindrome Check: Verify if a given string is a palindrome.
• Reverse a String: Write a program to reverse the characters of a string.
• Count Frequency of Characters: Count the frequency of each character in a string.
• Anagram Check: Check if two strings are anagrams of each other.
• Convert String Case: Convert lowercase characters of a string to uppercase and vice versa.
Remove Duplicates from a String: Eliminate duplicate characters from an input string.
4. Sorting and Searching Algorithms:
• Bubble Sort: Implement the bubble sort algorithm for an integer array.
• Insertion Sort: Implement insertion sort for an integer array.
• Quick Sort: Implement quick sort for a given array of numbers.
• Binary Search: Write a program to perform binary search on a sorted array.
5. Conversions:
• Decimal to Binary Conversion: Convert a decimal number to its binary equivalent.
• Binary to Decimal Conversion: Convert a binary number to its decimal equivalent.
• Fahrenheit to Celsius: Convert temperature from Fahrenheit to Celsius.
• String to Integer Conversion: Convert a string to an integer without using in-built functions like Integer.parseInt().
MOST COMMONLY GIVEN PROGRAMMING QUESTIONS IN INTERVIEW ROUND IN TCS
TCS NQT (National Qualifier Test)
1. Check for Leap Year
o Write a program to determine if a given year is a leap year.
2. Fibonacci Sequence
o Generate the Fibonacci series up to n terms.
3. Prime Number Check
o Verify if a given number is a prime number.
4. Sum of Natural Numbers
o Calculate the sum of the first n natural numbers.
5. Array Rotation
o Rotate an array K times to the right.
6. Find Maximum and Minimum in an Array
o Write a program to find the maximum and minimum elements in an array.
7. Palindrome String Check
o Check if a given string is a palindrome.
8. Binary Search Implementation
o Implement binary search on a sorted array.
9. Armstrong Number Check
o Determine if a given number is an Armstrong number.
10. Reverse a String
o Write a program to reverse the characters of a string.
TCS Digital
1. Two Sum Problem
o Given an array of integers, return the indices of the two numbers that add up to a specific target.
2. Find Duplicate in an Array
o Find duplicates in an array in O(n) time and O(1) space.
3. Find the Longest Substring Without Repeating Characters
o Given a string, find the longest substring that contains no repeated characters.
4. Implement Merge Sort
o Sort an array using the merge sort algorithm.
5. Kth Largest Element in an Array
o Find the Kth largest element in a given array.
6. Palindrome Number
o Check whether a given integer is a palindrome.
Move Zeros in an Array
o Move all the zeros to the end of an array while maintaining the relative order of other elements.
8. Maximum Subarray Problem
o Implement Kadane's algorithm to find the maximum sum of a contiguous subarray.
9. Valid Parentheses
o Write a program to check if a string of parentheses is valid.
10. Climbing Stairs Problem
o Given n stairs, find the number of ways you can climb the stairs (either 1 or 2 steps at a time).
TCS Ninja
1. Check if Array is Sorted
o Write a program to check if a given array is sorted or not.
2. Bubble Sort Algorithm
o Implement bubble sort on a given array.
3. Sum of Array Elements (The image cuts off here, but it's reasonable to assume this would ask for a program to
calculate the sum of all elements in an array.)
Count the Frequency of Characters in a String
o Given a string, count the frequency of each character.
6. Find the Second Largest Element in an Array
o Write a program to find the second largest element in an array.
7. Perfect Number Check
o Determine if a number is a perfect number.
8. Factorial of a Number
o Write a program to calculate the factorial of a given number.
9. Palindrome Number
o Check if a number is a palindrome.
10. Sort an Array of 0s, 1s, and 2s
o Sort an array containing only 0s, 1s, and 2s without using any sorting algorithm.
Reverse a Linked List
o Reverse a singly linked list iteratively and recursively.
2. Fibonacci Series Using Recursion
o Generate Fibonacci numbers using recursion.
3. Check if a String is Palindrome
o Verify if a string reads the same backward as forward.
4. Find the Middle of a Linked List
o Use the fast and slow pointer approach to find the middle node.
5. Bubble Sort Algorithm
o Implement bubble sort to sort an array.
6. Remove Duplicates from a Sorted Linked List
o Remove duplicates from a sorted linked list.
7. Maximum Sum Subarray (Kadane's Algorithm)
o Find the maximum sum of a contiguous subarray.
8. Check if a Tree is a Binary Search Tree
o Verify whether a given binary tree is a BST.
9. Binary Search
o Implement binary search on a sorted array.
10. Insertion Sort Algorithm
o Implement insertion sort to arrange an array.
11. Find the nth Node from the End of a Linked List
o Given a linked list, find the nth node from the end.
Merge two sorted arrays into one sorted array.
14. Balanced Parentheses
o Check if a string of parentheses is balanced.
15. Intersection of Two Linked Lists
o Find the intersection point of two linked lists.
16. Sorting a Stack Using Recursion
o Sort elements of a stack using recursion.
17. Find the Minimum Element in a Stack
o Design a stack that supports finding the minimum element in O(1) time.
18. Reverse a String Using Stack
o Reverse a given string using a stack.
19. Check for Anagrams
o Given two strings, check whether they are anagrams of each other.
20. Move Zeroes to the End of Array
o Move all zeroes to the end of an array without affecting the order of non-zero elements.
TCS Digital - 20 DSA Questions
1. Two Sum Problem
o Find two numbers in an array that sum up to a specific target.
2. Find the Longest Palindromic Substring
o Given a string, find the longest palindromic substring.
3. Merge Intervals
o Merge overlapping intervals from a list.
4. Quick Sort Algorithm
o Implement quick sort to sort an array.
5. Find the Kth Largest Element in an Array
o Find the Kth largest element using a heap.
6. Trapping Rain Water
o Calculate how much water can be trapped between bars after rain.
7. Longest Common Subsequence
o Find the longest common subsequence between two strings.
• Find the top K most frequent elements in an array.
9. Binary Tree Level Order Traversal
o Implement level order traversal of a binary tree.
10. Longest Increasing Subsequence
o Find the longest increasing subsequence in an array.
11. Rotate Matrix by 90 Degrees
o Rotate a square matrix by 90 degrees.
12. Nth Fibonacci Number Using Dynamic Programming
o Calculate the nth Fibonacci number using dynamic programming.
13. Flatten a Multilevel Doubly Linked List
o Flatten a multi-level doubly linked list.
14. Find the First Missing Positive
o Find the smallest missing positive integer from an unsorted array.
15. Zigzag Level Order Traversal of a Binary Tree
o Perform zigzag level order traversal.
16. Find the Lowest Common Ancestor in a Binary Tree
o Find the lowest common ancestor of two nodes in a binary tree.
17. Detect Cycle in a Directed Graph
o Detect if a cycle exists in a directed graph using DFS.
18. Median of Two Sorted Arrays
o Find the median of two sorted arrays.
19. Merge K Sorted Linked Lists (The image cuts off here, but it's reasonable to assume this would ask to merge k
sorted linked lists into one sorted linked list.)
• Given an infinite supply of coins of different denominations, find the minimum number of coins to make a specific
amount.
TCS Ninja - 20 DSA Questions
1. Check if Array is Sorted
o Write a function to check whether an array is sorted.
2. Find the Missing Number in an Array
o An array contains numbers from 1 to n with one number missing. Find the missing number.
3. Find the Second Largest Element in an Array
o Find the second largest number in an array.
4. Find Intersection of Two Arrays
o Return the intersection of two arrays.
5. Detect Cycle in an Undirected Graph
o Detect if a cycle exists in an undirected graph.
6. Remove Duplicates from Unsorted Linked List (The rest of the list is cut off in the image.)
7. Count Inversions in an Array
o Count the number of inversions in an array (using merge sort).
8. Reverse a Queue Using Recursion
o Reverse the elements of a queue using recursion.
9. Convert Binary Tree to Doubly Linked List
o Convert a binary tree into a doubly linked list.
10. Check for Balanced Binary Tree
o Check if a binary tree is height-balanced.
11. Find Majority Element in an Array
o Find the element that appears more than half the time in an array.
12. Sort Colors
o Sort an array of 0s, 1s, and 2s without using any sorting algorithm.
13. Remove Loop in Linked List
o Detect and remove a loop in a linked list.
14. Check if a Binary Tree is Symmetric
o Check if a binary tree is a mirror of itself. (The image cuts off here, but it's likely the question would
continue as shown below.)
o Check if a binary tree is a mirror of itself.
• Check if a binary tree is a mirror of itself.
15. Find Duplicates in O(n) Time and O(1) Space
o Find all duplicate numbers in an array in O(n) time and constant space.
16. Find the Median of a Stream of Integers
o Find the median of a stream of integers.
17. K Closest Points to Origin
o Find the K points closest to the origin (0,0).
18. Word Search
o Given a 2D board and a word, find if the word exists in the grid.
19. Serialize and Deserialize a Binary Tree
o Serialize and deserialize a binary tree.
20. Next Greater Element
o Given an array, for each element find the next greater element.