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: Aspirants who pass in the Online Test will qualify to the coding test process. The coding test will be conducted for the process to check the candidate’s capability. The Tech Mahindra coding questions will be asked in any language. In the below section, we have provided the Java, C, C++, and Python Coding Questions with Solutions. With the clear Explanation, we have provided all the details here. Solve the Frequently Asked coding test Questions to help with your study. Before entering the coding test, aspirants can start their preparation by downloading or viewing the practice questions.
Here we have provided the study material for the coding test. Tech Mahindra will conduct the Coding Test for each hiring Process. Every year, they hire many employees to fill many positions. As of now, they are going to hold the test for the Tech Mahindra Coding. So, aspirants who are going to attend this hiring process kindly check out the Tech Mahindra Coding Questions & Answers before attending the process. More details like 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+" ");
}
}
}
#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>> |
Follow regularly our Dailyrecruitment.in site to get upcoming all up-to-date information.
Govt Jobs by Qualifications
Education & Vacancies | Salary | Apply Link |
---|---|---|
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 |