FarEye
Tech Mahindra Interview Questions and Answers
Q1. What is LRU caching and how it can be implemented?
LRU caching is a technique to store frequently used data in cache memory to improve performance.
LRU stands for Least Recently Used.
It removes the least recently used item from the cache when the cache is full.
It uses a doubly linked list and a hash map to implement the cache.
When an item is accessed, it is moved to the front of the list.
When the cache is full, the item at the end of the list is removed.
Example: Java LinkedHashMap and Python OrderedDict use LRU caching.
Q2. Print the all anagrams of same type in same line from array of Strings
Print all anagrams of same type in same line from array of Strings
Create a HashMap with sorted string as key and list of anagrams as value
Iterate through array and add each string to corresponding list in HashMap
Print all values in HashMap
Q3. Explain producer-consumer problem and write code using thread.
Producer-consumer problem involves synchronization between threads to avoid race conditions.
Producer produces data and adds it to a shared buffer
Consumer consumes data from the shared buffer
Synchronization is required to avoid race conditions
Code example: https://www.geeksforgeeks.org/producer-consumer-solution-using-threads-in-java/
Q4. Check a tree is BST or not.
To check if a tree is a BST or not.
Traverse the tree in-order and check if the values are in ascending order.
For each node, check if its value is greater than the maximum value of its left subtree and less than the minimum value of its right subtree.
Recursively check if the left and right subtrees are also BSTs.
Q5. Reverse a single linked list.
Reverse a single linked list.
Iterate through the list and change the direction of the pointers
Keep track of the previous, current and next nodes
Set the head of the list to the last node after reversing
Q6. Features added in Java 8
Java 8 introduced lambda expressions, functional interfaces, streams, and default methods.
Lambda expressions allow functional programming in Java.
Functional interfaces are interfaces with a single abstract method.
Streams provide a way to process collections of data in a functional way.
Default methods allow interfaces to have implementation.
Date and Time API improvements.
Nashorn JavaScript engine added.
Interview Process at Tech Mahindra
Top Software Developer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month