Tech Mahindra Coding Questions

Tech Mahindra Coding Questions
Tech Mahindra Coding Questions

Introduction

Tech Mahindra is a great company to join for both professionals and freshers alike. The company provides ample opportunities and massive scope for growth in the field of programming or IT in general. Cracking the Tech Mahindra Test is essential in order to get into this Indian MNC with a respectable track record. The first round of the Tech Mahindra Test incorporates the coding test in the Technical Section alongside Technical MCQs based on Object-Oriented programming, Networks, RDBMS, C, C++, Java, general IT/Computer Science, Linux and other operating systems.

Fundamentally, the first round consists of three sections, the Aptitude section, the English Essay and finally, the Technical Test. In the technical section, candidates are given 25 technical MCQs and a single coding test that must be completed within 65 minutes. Due to the nature of the technical section, candidates are suggested to spend only about 15 to 20 minutes on the coding test.

The coding test is of medium difficulty, which means that it is not very tough, however, it is not easy to pass either. Practicing some coding questions from last year’s Tech Mahindra Test can definitely help you gain an edge during the next Tech Mahindra coding test. Let’s have a look at some coding questions that are solved in C and C++. Most of the coding questions during previous recruitment drives are focused on fundamental programming, largely based on arrays. 


Resources to Prepare for Tech Mahindra Interviews

Before we jump into the top Tech Mahindra Coding Questions. Coding Ninjas has launched the best course for complete preparation of Tech Mahindra Interviews, TCS, IBM, Infosys, and other similar exams and companies.

Course Highlights:

  • Covers everything you need to learn, Programming(C++/Java/Python), Aptitude(Quantitative Analysis, Logical Reasoning, Verbal Reasoning).
  • Faculties are best in the industry: Arun Sharma (India’s best selling author for CAT Aptitude Books) and Ankush Singla(Ex-Facebook, Ex-Amazon)
  • 1-1 live doubt support via Audio/Video Calls whenever you are stuck.
  • Coding Ninjas Placement Cell access.

Enroll Now in Tech Mahindra Interview Prep Course

Tech Mahindra Coding Questions in C

1. Here are some Tech Mahindra Coding Questions from 2020 which are solved in C: Build a program for calculating and returning the sums of absolute differences between adjacent numbers in arrays of positive integers. This must be calculated from the position determined by the current user.

In the case of this coding problem, you use three positional arguments through a findTotalSum function. The three inputs you would require are the number of elements inside the array, the elements in the array and the position from where this function will take place.

For example, suppose the total number of elements is 5 and these are the elements:

1 2 3 6 4

Then, if we decide to start from the 3rd position or enter 3 as input, the function will occur from ‘3’, the 3rd number in the array.

Hence, the sum would be a total of (6-3)+(4-6)= 5

Here is the code:

#include <stdio.h>
#include <stdlib.h>
int findTotalSum(int n, int arr[], int start)
{
    int difference, sum=0;
    for(int i=start-1; i<n-1; i++)
    {
        difference = abs(arr[i]-arr[i+1]);
        sum = sum + difference;
    }
    return sum;
}
int main()
{
    int n;
    int start;
    scanf("%d",&n);
    int array[n];
    for(int i=0; i<n; i++)
    {
        scanf("%d",&array[i]);
    }
    scanf("%d",&start);
    int result = findTotalSum(n, array, start);
    printf("\n%d",result);
    return 0;
}

2. Build a program that will allow you to find out how many clothing pieces in total of a certain length can be extracted from a particular number of cloth pieces. We can take the required length for each clothing piece as 10 feet.

In this case, we must first decide upon the length unit as feet and determine the inputs we need. For this function, we will need two inputs, first the number of pieces ( in the array) and the size of each piece in feet inside the array. 

A cloth merchant has some pieces of cloth of different lengths. He has an order of curtains of length 12 feet. He has to find how many curtains can be made from these pieces. Length of pieces of cloth is recorded in feet. 

For example, suppose the total number of elements is 3 and these are the elements:

0 10 40

Then, the first input is 3 followed by the second input of 0, 10 and 40.

Hence, the sum would be a total of 0 + (10/10) + (40/10) = 5

Thus, there could be 5 pieces of clothing extracted from these 3 pieces of cloth of variable sizes.

Here is the code:

#include <stdio.h>
int findTotalPieces(int n, int arr[])
{
    int feet, total = 0;
    for(int i=0; i<n; i++)
    {
        feet = arr[i] / 10;
        total = total + feet;    
    }
    return total;
}
int main()
{
    int n;
    scanf("%d",&n);
    int array[n];
    for(int i=0; i<n; i++)
    {
        scanf("%d",&array[i]);
    }
    int result = findTotalPieces(n, array);
    printf("%d",result);
    return 0;
}

Practicing previous year coding questions such as the ones above will definitely help you solve Tech Mahindra coding questions 2021 in C with ease.

Tech Mahindra Coding Questions in C++

Here are some more previous Tech Mahindra coding questions with answers in C++:

1. Calculate the total interest on loans for an array of amounts. However, till the amount of 2000, there is no interest applicable, but, there is a 20% interest applicable for the remaining amounts in the array.

In this case, we will be writing a calculate TotalInterest function that receives the first input as the number of amounts in the array and the second input as the array of amounts.

For instance, if there are 5 amounts with the first input as 5 and the amounts being 2000, 4000, 6000, 8000 and 10000.

The total sum would be = 20% of 4000 + 20% of 6000 + 20% of 8000 + 20% of 10000 = 5600 (as the 2000 will not be considered for interest)

Here is the code:

#include<iostream>
using namespace std;
int calculateTotalInterest(int n, int arr[])
{
    int tax=0;
    for(int i=0;i<n;i++)
    {
        tax=tax+(int)((arr[i]-1000)*0.2);
    }
    return tax;
}
int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    cout<<calculateTotalInterest(n,arr);
    return 0;
}

2. Write code for returning the differences between the sums of even and odd numbers in an array of positive integers.

In this case, we will be writing a calculateOddEvenDifference function that receives the first input as the number of positive integers in the array and the second input as the array of positive integers.

For instance, if there are 4 numbers as the first input and the numbers are 13, 8, 9 and 4, the difference of the sum of odd numbers and the sum of even numbers would be = (13+9) – (8+4) = 22 – 12 = 10

Here is the code:

#include<iostream>
using namespace std;
int calculateOddEvenDifference(int n, int arr[])
{
    int odd=0,even=0;
    for(int i=0;i<n;i++)
    {
        if(arr[i]%2==0)
            even+=arr[i];
        else
            odd+=arr[i];
    }
    return odd-even;
}
int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    cout<<calculateOddEvenDifference(n,arr);
    return 0;
}

Frequently Asked Questions

Is there coding in Tech Mahindra?

Yes, there is coding in the Tech Mahindra Test since the first round. There are Tech Mahindra second round coding questions once you finish the first round.

Does Tech Mahindra 2021 have negative marking?

No, Tech Mahindra 2021 Test does not have any negative marking.

What is the syllabus of Tech Mahindra?

The syllabus for Tech Mahindra Coding Test is based on mainly arrays and foundational programming while the technical MCQs are based on operating systems, programming languages and other concepts such as Object-Oriented Programming.

What is Tech Test in Tech Mahindra?

The Tech Test is the technical session composed of 26 questions in the first round of the Tech Mahindra Test.

What is the salary for freshers in Tech Mahindra?

The salary for freshers offered by Tech Mahindra is an average of Rs. 3,50,000 per annum.

How many rounds are there in Tech Mahindra 2021?

There are a total of 3 rounds with 2 composed of different sections of assessments and the final round being an interview round.

Is the Technical Section tough?

No, the technical section is of medium difficulty and can easily be cracked by preparing Tech Mahindra coding questions in Java, C++ or C. You can also choose to practise Tech Mahindra coding questions in Python.

How should I prepare for the coding test?

You can easily prepare by practising problems in arrays from Coding Ninjas CodeStudio and by checking previous year questions in order to solve Tech Mahindra coding questions in 2021 in Java, C or C++. You can also additionally check Faceprep Tech Mahindra coding questions and exam pattern as well.

Is Tech Mahindra a good company to work at?

Yes, Tech Mahindra has a great track record and is an amazing company to work at. The possibilities are endless with this MNC hailing from India.

Key Takeaway

Even though Tech Mahindra’s Technical section is not known for being easy, one can easily pass the first round and even the later rounds with enough practice. You must choose the language you are comfortable with such as C, C++, Java, or even Python, and use the programming knowledge at your disposal to solve the coding problems.

One must take care to not only solve previous year’s questions but also discover potentially important questions from other sources such as CodeStudio in order to get in more practice. Practice is key to cracking this technical test and you must get enough of it, especially focusing on problems related to arrays.

Exit mobile version