Add office photos
Employer?
Claim Account for FREE

FarEye

3.1
based on 203 Reviews
Filter interviews by

Tech Mahindra Interview Questions and Answers

Updated 5 Feb 2024

Q1. What is LRU caching and how it can be implemented?

Ans.

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.

Add your answer

Q2. Print the all anagrams of same type in same line from array of Strings

Ans.

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

Add your answer

Q3. Explain producer-consumer problem and write code using thread.

Ans.

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/

Add your answer

Q4. Check a tree is BST or not.

Ans.

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.

Add your answer
Discover Tech Mahindra interview dos and don'ts from real experiences

Q5. Reverse a single linked list.

Ans.

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

Add your answer

Q6. Features added in Java 8

Ans.

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.

Add your answer
Contribute & help others!
Write a review
Share interview
Contribute salary
Add office photos

Interview Process at Tech Mahindra

based on 1 interviews
Interview experience
5.0
Excellent
View more
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Top Software Developer Interview Questions from Similar Companies

3.7
 • 243 Interview Questions
4.0
 • 39 Interview Questions
3.6
 • 18 Interview Questions
2.9
 • 10 Interview Questions
3.5
 • 10 Interview Questions
4.2
 • 10 Interview Questions
View all
Share an Interview
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
70 Lakh+

Reviews

5 Lakh+

Interviews

4 Crore+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter