Tech Mahindra Coding Questions & Answers 2024 (Freshers/ Exp), Check Tech Mahindra Coding MCQ Questions 2024

Tech Mahindra Coding Questions & Answers 2024 | Tech Mahindra Coding Questions in Java | Tech Mahindra Coding Questions in Python | Tech Mahindra Coding Questions in C | Tech Mahindra Coding Previous Year Questions 

Tech Mahindra Coding Questions & Answers 2024: Both new graduates and professionals could think about working with Tech Mahindra. The coding test is medium complexity, meaning that while passing it is not impossible, it is also not very simple. If you practiced any of the code questions from the previous year’s test, you would undoubtedly have an advantage in the upcoming Tech Mahindra coding test. Let’s look at some test patterns, code problems, and solutions for C, C++, Java, Python, and Supercoder. In the below section, you may get the Tech Mahindra Coding Questions and Answers/ Tech Mahindra Coding Questions With Solutions

A unique technique for assessing a candidate’s capacity for problem-solving is offered by Tech Mahindra. On their blog, they frequently hold coding competitions. Should you successfully finish the challenge, you might receive an interview request. This tutorial will teach you all there is to know about Tech Mahindra Coding Previous Year Questions/ Tech Mahindra Coding Model Questions. More details like Tech Mahindra Coding Questions and Answers, Tech Mahindra Coding Questions and Answers For Freshers, Tech Mahindra Interview Questions and Answers, Tech Mahindra Cut Off, Salary, Hike, Increment, Annual Appraisal, etc. are available on this page

Tech Mahindra Coding Questions & Answers 2024 For Freshers

Easy:

  • Find GCD and LCM of two numbers.
  • Program to check whether the given number is prime or not.
  • To check whether the number is Armstrong.
  • Program to check number is strong or not.
  • Check whether the given number is Automorphic or not.
  • To print the Fibonacci series up to the n value.
  • Prime number printing within a given range.

Medium:

  • Pyramid pattern printing program.
  • Reversing a number.
  • Printing the Armstrong numbers between the given intervals.
  • Converting Binary numbers to Decimal and vice versa.
  • Decimal to Octal conversion.
  • Binary to octal conversion.

Hard:

  • Program for Palindrome pattern printing.
  • Removing the vowels from the string.
  • Finding the frequency of the characters from the given string.
  • Program to find roots of the quadratic equation.
  • Diamond printing pattern programs.
  • Finding the largest palindrome number from the given array.

Tech Mahindra Coding Questions With Solutions 2024 For Freshers

Print the length of a string without using the string functions.

import java.util.*;
class ninjaSolution {
    public static void main(String[] args) {
        String str = "Hey Ninja!!";
        int len=0;
        char[] strCharArray=str.toCharArray();
        for(char c:strCharArray){
            len++;
        }
        System.out.println("Lenght of string "+str+" is: "+len);
    }
}

Write a code to check whether a number is prime or not.

import java.util.*;
class ninjaSolution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Please enter a number");
        int num = sc.nextInt();
        int count=0;
        for(int i=2;i<num/2;i++){
            if(num%i==0)
                count++;
        }
        if(count>0)
            System.out.println("Number is not prime");
        else
            System.out.println("Number is prime");
    }
}

Write a code to add two numbers without using arithmetic operations.

class ninjaSolution {
    public static void main(String[] args) {
        int num1 = 10, num2 = 50;
        while (num2 != 0){
            int carry = (num1 & num2) ; //CARRY is AND of two bits
          
            num1 = num1^num2; //SUM of two bits is A XOR B
          
            num2 = carry << 1; //shifts carry to 1 bit to calculate sum
        }
        System.out.println("Sum of 10 and 50 is: "+num1);
    }
}

Write a code to print numbers from 1 to 10 without using a loop or recursion in C++.

#include <iostream>
using namespace std;
 
template<int n>
class PrintZeroToN
{
public:
   static void display()
   {
       PrintZeroToN<n-1>::display();
       cout << n << endl;
   }
};
 
template<>
class PrintZeroToN<0>
{
public:
   static void display()
   {
       cout << 0 << endl;
   }
};
int main()
{
   const int n = 10;
   PrintZeroToN<n>::display();
   return 0;
}

Print the address of a variable without using a pointer.

We can directly print the address of a variable using the ‘&’ symbol in c,

#include <stdio.h>
int main()
{
   int x;
   printf("Address of x: %p\n", &x);
   return 0;
}

Write a program to check whether the given number is even or odd

import java.util.*;
class ninjaSolution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Please Enter a number!!");
        int num = sc.nextInt();
        if(num%2==0)
            System.out.println(num+" is even");
        else
            System.out.println(num+" is odd");
    }
}

Write a program to print the Fibonacci series.

import java.util.*;
class ninjaSolution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Please enter the limit!!");
        int limit = sc.nextInt();
         int n1 = 0, n2=1, n3;
        System.out.println("Fibonacci series upto "+limit+" numnber");
        System.out.print("\n\n"+n1+" "+n2+" ");
        for(int i=2;i<limit;i++){
            n3 = n1+n2;
            n1 = n2;
            n2 = n3;
            System.out.print(" "+n3+" ");
        }
    }
}

Tech Mahindra Coding Questions & Answers For Experienced

Question) You want to buy a particular stock at its lowest price and sell it later at its highest price. Since the stock market is unpredictable, you steal the price plans of a company for this stock for the next N days.
Find the best price you can get to buy this stock to achieve maximum profit.

Note: The initial price of the stock is 0.

Input Specification:

Input1: N, number of days
Input2: Array representing change in stock price for the day.

Output Specification:

Your function must return the best price to buy the stock at.

Example1:

Input1: 5
Input2: (-39957,-17136,35466,21820,-26711}
Output: -57093
Explanation: The best time to buy the stock will be on Day 2 when the price of the stock will be -57093.

Example2:

Input1: 5
Input2: (-39957, -17136, 1, 2, -26711)
Output: -80801
Explanation: The best time to buy the stock will be on Day 5 when the price of the stock will be -83801.

Example3:

Input1: 9
Input2: (-4527,-1579,-38732,-43669,-9287,-48068,-30293,-30867,18677}
Output: -207022
Explanation: The best time to buy the stock will be on Day 8 when the price of the stock will be -207022.

C++ PROGRAM:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N, ans, price;
    cin>>N;
   
    int arr[N];
    
    for (int i = 0; i < N; i++)
        cin>>arr[i];
    
    price = 0;
    ans = 0;
    for (int i = 0; i < N; i++)
    {
        price = price + arr[i];
        if (ans > price)
            {
                ans = price;
            }
    }
    cout << ans;
}

C PROGRAM:

#include<stdio.h>
int main()
{
    int N, ans, price;
    scanf("%d", &N);
   
    int arr[N];
    
    for (int i = 0; i < N; i++)
        scanf("%d", &arr[i]);
    
    price = 0;
    ans = 0;
    for (int i = 0; i < N; i++)
    {
        price = price + arr[i];
        if (ans > price)
            {
                ans = price;
            }
    }
    printf("%d", ans);
}

PYTHON PROGRAM

n = int(input())
arr = []
for i in range(n):
   arr.append(int(input()))
min = 0
for i in range(1, n):
   if sum(arr[:i]) < min:
       min = sum(arr[:i])
print(min)

Question) Given a positive whole number n, find the smallest number which has the very same digits existing in the whole number n and is greater than n. In the event that no such certain number exists, return – 1.

Note: that the returned number should fit in a 32-digit number, if there is a substantial answer however it doesn’t fit in a 32-bit number, return – 1.

Example 1:

Input: n = 12
Output: 21
Explanation: Using the same digit as the number of permutations, the next greatest number for 12 is 21.

Example 2:

Input: n = 21
Output: -1
Explanation: The returned integer does not fit in a 32-bit integer

C++ PROGRAM

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

void swap(char *a, char *b)
{
	char temp = *a;
	*a = *b;
	*b = temp;
}

void findNext(char number[], int n)
{
	int i, j;

	for (i = n-1; i > 0; i--)
		if (number[i] > number[i-1])
		break;

	if (i == 0)
	{
		cout << "Next number is not possible";
		return;
	}

	int x = number[i-1], smallest = i;
	for (j = i+1; j < n; j++) if (number[j] > x && number[j] < number[smallest])
			smallest = j;

	swap(&number[smallest], &number[i-1]);


	sort(number + i, number + n);

	cout << number; return; } int main() { char digits[]; cin >> digits
	int n = strlen(digits);
	findNext(digits, n);
	return 0;
}

JAVA PROGRAM

import java.util.*;
public class Main
{
	static void swap(char ar[], int i, int j)
	{
		char temp = ar[i];
		ar[i] = ar[j];
		ar[j] = temp;
	}
	
	static void findNext(char ar[], int n)
	{
		int i;
		
		for (i = n - 1; i > 0; i--)
		{
			if (ar[i] > ar[i - 1]) {
				break;
			}
		}
		
		if (i == 0)
		{
			System.out.println("Not possible");
		}
		else
		{
			int x = ar[i - 1], min = i;
			
			
			for (int j = i + 1; j < n; j++)
			{
				if (ar[j] > x && ar[j] < ar[min])
				{
					min = j;
				}
			}
		
			swap(ar, i - 1, min);
			Arrays.sort(ar, i, n);
			
			for (i = 0; i < n; i++)
				System.out.print(ar[i]);
		}
	}

	public static void main(String[] args)
	{
	    Scanner sc = new Scanner(System.in);
	    int n =sc.nextInt();
	    String s = sc.next();
		char digits[] = s.toCharArray();
		
		findNext(digits, n);
	}
}

PYTHON PROGRAM

arr = []
def permute(s,ans):
    n = len(s)
    if (n == 0):
        arr.append(ans)
        return
    for i in range(n):
        ch = s[i]
        L = s[0:i]
        R = s[i + 1:]
        REM = L+ R
        permute(REM,ans + ch)
ans= ""
s = input()
n = len(s)
permute(s,ans)
arr = list(set(arr))
arr.sort()
ind = arr.index(s)
if(ind == len(arr)-1):
    print(-1)
else:
    print(arr[ind+1])
JOB ALERT ON INSTAGRAM FOLLOW NOW>>
JOB ALERT ON YOUR EMAIL DAILY SUBSCRIBE NOW>>

Keep an eye on Dailyrecruitment.in for the most up-to-date information about upcoming exams and results. Find out about official notices, Exam Patterns, Syllabus, Previous Question Papers, Expected Cut Off, Results, Merit List, Study Materials, and much more. Now is the time to bookmark in order to take advantage of even more amazing career opportunities.

Govt Jobs by Qualifications

Education & Vacancies Salary Apply Link
10th Pass Govt Jobs - 5,000 Vacancies Rs. 5,200 - 63,200 Apply Now
12th Pass Govt Jobs - 18,000+ Vacancies Rs. 5,200 - 92,300 Apply Now
ITI Pass Jobs - 3,500 Vacancies Rs. 5,200 - 35,000 Apply Now
Any Graduate Jobs - 19,100 Vacancies Rs. 5,200 - 92,300 Apply Now
Central Govt Jobs Rs. 5,200 - 17,000 Apply Now
Bank Jobs - 1,000 Vacancies Rs. 5,200 - 29,200 Apply Now
Diploma Jobs - 9,300 Vacancies Rs. 5,200 - 35,000 Apply Now
BTech/BE Jobs - 18,000 Vacancies Rs. 15,000 - 1,00,000 Apply Now
Data Entry Jobs - 1,300 Vacancies Rs. 5,200 - 29,200 Apply Now
Private Jobs Rs. 10,000 - 67,700 Apply Now