Home Paper Tech Mahindra Previous Year Coding Questions

Tech Mahindra Previous Year Coding Questions

by Anup Maurya
6 minutes read
Tech Mahindra Previous Year Coding Questions

Question 6

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

Note : You are expected to write code in the findTotalCurtains function only which receive the first parameter as the number of items in the array and second parameter as the array itself. You are not required to take the input from the console.

Example

Finding the total curtains from a list of 5 cloth pieces.

Input
input 1 : 5
input 2 : 3 42 60 6 14

Output
9

Explanation
The first parameter 5 is the size of the array. Next is an array of measurements in feet. The total number of curtains is 5 which is calculated as under

3 -> 0
42 -> 3
60 -> 5
6 -> 0
14 -> 1
total = 9

[Tech Mahindra Coding Questions 2023]

Question 7

Given a decimal number as input, we need to write a program to convert the given decimal number into an equivalent binary number.

Example

Convert 17 and 33 into it’s respective decimal form

Input

Input 1 : 17
Input 2 : 33

Output

Ouput1 : 111
Output2 : 100001

[Tech Mahindra Coding Questions 2024]

Question 8

Given an array with both +ive and -ive integers, return a pair with the highest product.

Input

Input1 : arr[] = {1, 4, 3, 6, 7, 0}  
Input2 : arr[] = {-1, -3, -4, 2, 0, -5} 

Output

Output1 : {6,7}
Output2 : {-4,-5}

[Tech Mahindra Coding Questions 2024]

Question 9

You are given an array, You have to choose a contiguous subarray of length ‘k’, and find the minimum of that segment, return the maximum of those minimums.

Input 

1 → Length of segment x =1
5 → size of space n = 5
1 → space = [ 1,2,3,1,2]
2
3
1
2

Output

3

Explanation

The subarrays of size x = 1 are [1],[2],[3],[1], and [2],Because each subarray only contains 1 element, each value is minimal with respect to the subarray it is in. The maximum of these values is 3. Therefore, the answer is 3.  

[Tech Mahindra Coding Questions 2024]

Question 10

Write a program to calculate the total bill tax amount for a list of billing amounts passed as an array of long integers.

Up to the amount of 1000, there is no tax applicable, subsequently, a flat tax of 10% is applicable for the remaining amount as per the tax rate.

Note: 

All calculations and results should be integer-based ignoring fractions

You are expected to write code int the calcTotalTax function only which will receive the first parameter as the number of items in the array and the second parameter is the array itself. You are not required to take input from the console.

Example

Calculating total tax for a list of 5 billing amounts

Input

5

1000 2000 3000 4000 5000

Output

1000

Explanation

The first parameter (5) is the size of the array. Next is an array of billing amounts For the first amount there will be 0 tax and for the next amount, it will be 10% of(2000-1000)=100 and so on.

The sum of all the tax amounts will be (0+100+200+300+400=1000)

[Tech Mahindra Coding Questions 2024]

Question 11

A company is transmitting data to another server. The data is in the form of numbers. To secure the data while transmitting they want to obtain a security key that will be obtained with the data. The security key is identified as the count of the unique repeating digits in the data.

Write an Algorithm to find the security key for the data.

Input: The input Consist of an integer – data, representing the data to be transmitted.

Output : Print An integer representing the security key for the given data.

Input 1:
578378923
Output 1:
3

Explanation:
The repeated digits in the data are 7, 8 and 3. So the security key is 3.

[Tech Mahindra Coding Questions July 2024]

Question 12

Caesar cipher encryption is done by replacing a letter with 3 letters to left of it.
Example: a is replaced by x, d is replaced by a .
You would be given a encrypted cipher text, decrypt it and print the plaintext.’

Example 1 : yhqgz
Output 1 : bktjc
Example 2 : abcde
Output 2 : defgh

[Tech Mahindra Coding Questions July 2024]

related posts

Leave a Comment

Enable Notifications OK No thanks