Home Get Hired Tech Mahindra Coding Questions: Problem Statements & Tips for Freshers

Table of content:

Tech Mahindra Coding Questions: Problem Statements & Tips for Freshers

Tech Mahindra’s recruitment process emphasises a candidate’s technical prowess and problem-solving skills. Among its various evaluation parameters, coding questions stand out as a decisive factor. Whether you're aiming for a software developer role or any tech-based position, acing the coding section is crucial. 

This article provides a detailed overview of coding question patterns, preparation tips, and actionable insights to help you secure a spot in Tech Mahindra.

Understanding Tech Mahindra Coding Questions

Question Categories

Tech Mahindra’s coding questions cover a mix of theoretical and practical programming challenges. Here are the key categories:

  • Data Structures: Arrays, Linked Lists, Trees, Graphs, and Stacks.
  • Algorithms: Sorting, Searching, Dynamic Programming, and Recursion.
  • Problem Solving: Logical puzzles requiring analytical and coding skills.
  • Error Fixing: Debugging provided code snippets.

Sample Questions

To give you a better idea, here’s a table showcasing typical coding challenges:

Category

Example Question

Difficulty

Arrays

Find the missing number in an array of size n.

Easy

Strings

Determine if a given string is a palindrome.

Easy

Dynamic Programming

Solve the Knapsack problem using recursion and memorisation.

Moderate

Sorting Algorithms

Write and explain the MergeSort algorithm.

Advanced

Binary Trees

Create a function to check if two binary trees are identical.

Moderate

Are you looking for Tech Mahindra coding questions? Click here to access coding practice sessions from moderate to challenging levels.

Top 5 Coding Problem Statements for Tech Mahindra

Problem Statement 1

You are given an array of votes each student has got in the student election in your university. You have to find the subsequence of votes of the students who can form a majority to run the student association. A majority is formed when the students have strictly received more than half of the total votes polled.

If there are multiple solutions, return the subsequence with minimum size and if there still exist multiple solutions, return the subsequence with the maximum total sum of all its elements. A subsequence of an array can be obtained by erasing some (possibly zero) elements from the array.

Input Format

The first line contains the length of the password array.

The second line contains an N number, each denoting the votes scored by the particular student.

Output Format

You have to print the list of votes scored by a student that would form the majority in non-increasing order.

Constraints

1<= Size of vote array<= 4*10^4

0<=Value at any index is<=100

Solution C++

Solution Java

Solution Python

Problem Statement 2

You are given a series of queries on the form (A, B), where A represents the count of the number B. For example, the query (3, 5) means the number 5 appears 3 times.

Your task is to compute the absolute difference between the numbers that have the highest and lowest frequencies (appearing at least once). If there are multiple numbers with the same frequency, choose the smallest number for the lowest frequency and the largest number for the highest frequency.

Input Format

The first line contains a single integer denoting the number of queries.

The second line onwards contains two space-separated integers denoting the queries.

Output Format

Output the maximum possible absolute difference between the numbers with the highest and lowest frequencies. If there are only two numbers with the same occurrence, the output should be 0.

Constraints

1 <= Q <= 10^5.

1 <= A, B <= 10^5.

Solution C++

Solution Java

Solution Python 

Problem Statement 3

During the night of the street race, there are N cars on the street, each with a given speed. The police will be alerted if the total number of speed variation pairs exceeds a certain threshold, X.

A pair of cars (i, j) has a speed variation if the absolute difference in their speeds is at least K. The total speed variation count is the number of such pairs where the speed difference is at least K.

You need to determine whether the total speed variation count is greater than the given threshold, X. If it is, the police will be alerted; otherwise, they will not.

Input Format

The first line contains three space-separated integers: N, the number of cars; K, the minimum speed difference for variation; and X, the alert threshold.

The second line contains N space-separated integers representing the speeds of the cars.

Output Format

Print YES if the total speed variation count exceeds X; otherwise, print NO.

Constraints

1 <= N <= 2 * 10^5

1 <= K, X <= 10^8

1 <= S[i] <= 10^8

Solution C++

Solution Java

Solution Python 

Problem Statement 4

You are given a string made up of only lowercase English letters. Your task is to find the length of the longest substring that is "good." You can change the last character of the string to help make the substring as long as possible.

A substring is called "good" if the difference between consecutive characters is exactly 1, and the characters are in ascending order (e.g., "abc" is good, but "cba" is not).

Note: str contains only lowercase English alphabet

Input Format

The first line contains a single string of lowercase English letters denoting str.

Output Format

Print the length of the longest "good" substring

Constraints

1 <= |str| <= 10^5

Solution C++

Solution Java

Solution Python

Problem Statement 5

Alice enjoys working with numbers and has discovered an interesting property about them. She realized that any number can be represented as a sequence of its digits. For example, the number 12 can be represented as the array digits of {1, 2}, and the number 1 can be represented as the array digits of {1}.

Alice defines a number as "good" if the absolute difference between every pair of consecutive digits in its array representation of digits is exactly 1.

For example, Number 1234 is a good number as it is in digit array {1, 2, 3, 4}. The difference between every consecutive pair is exactly 1.

Your task is to help Alice by finding all the "good" numbers from 0 to N, inclusive, where N is a given integer.

Note: All single-digit numbers are considered good, as there are no consecutive digits to compare.

Input Format

The first line of input contains a single integer N representing the upper limit of the range.

Output Format

Print all the "good" numbers from 0 to N, separated by spaces.

Constraints

1 <= N <= 10^5

Solution C++

Solution Java

Solution Python

Tips for Acing Tech Mahindra Coding Test 

  1. Analyse the Syllabus
    Begin by focusing on foundational programming concepts, including loops, conditions, and functions. Move on to advanced topics like dynamic programming and graph algorithms.
  2. Practice Consistently
    Regular coding practice on available online platforms and Tech Mahindra's official practice modules is key to improving speed and accuracy.
  3. Solve Previous Year's Papers
    Familiarising yourself with past Tech Mahindra coding questions offers insight into the difficulty level and frequently tested concepts.
  4. Time Management
    Simulate exam conditions while practising to learn effective time management and reduce stress during the actual test.
  5. Focus on Debugging
    Tech Mahindra often tests candidates’ debugging abilities. Practice identifying and fixing bugs in given code snippets to improve this skill.

Conclusion

Securing a position at Tech Mahindra demands strong coding skills and a strategic approach. Understanding the question patterns, practising consistently, and learning from past papers can significantly boost your chances. Embrace these insights and ace your coding test to take the first step toward an exciting career at Tech Mahindra. 

Frequently Asked Questions (FAQs)

1. What level of coding questions does Tech Mahindra include in its test?

The difficulty ranges from beginner to advanced, depending on the role you’re applying for.

2. Which programming languages are accepted?

Tech Mahindra allows candidates to choose from languages such as C, C++, Java, and Python.

3. How many coding problems are included in the test?

Typically, there are 1-2 coding questions to be solved within 45-60 minutes.

4. Where can I access previous Tech Mahindra coding questions?

Official resources on the Tech Mahindra careers portal, along with trusted coding platforms, provide access to past questions.

5. What are the key coding topics to focus on?

Arrays, Strings, Dynamic Programming, and Binary Trees are frequently tested topics.

Disclaimer: While we strive for accuracy, we do not guarantee its completeness or reliability. Readers are encouraged to verify all facts and statistics from the official company website or check independently before making decisions. 

Suggested reads:

Kaihrii Thomas
Senior Associate Content Writer

Instinctively, I fall for nature, music, humor, reading, writing, listening, traveling, observing, learning, unlearning, friendship, exercise, etc., all these from the cradle to the grave- that's ME! It's my irrefutable belief in the uniqueness of all. I'll vehemently defend your right to be your best while I expect the same from you!

TAGS
Placement
Updated On: 27 Nov'24, 10:35 AM IST