Please login

Prime

Prepinsta Prime

Video courses for company/skill based Preparation

(Check all courses)
Get Prime Video
Prime

Prepinsta Prime

Purchase mock tests for company/skill building

(Check all mocks)
Get Prime mock

Mindtree Coding Questions and Answers

MindTree Coding Questions and Answers

MindTree Coding Questions are mix of all basic programming concepts, Dynamic Programming, data structures and algorithm etc.
In exam, you will get 3 different sections based on the above concepts such as array, string, normal mathematics.

In mindtree, coding test section is divided into 3 categories such as:-

  • Implementation Ques- 3 Ques
  • DS/Algo Ques- 3 Ques
  • Advanced Algo Ques- 2 Ques

Mindtree
Coding Questions and Answers

MindTree Coding Ques are divided into the following sections.

  • Implementation Ques (50 Marks)
  • DS/Algo Ques (75 Marks)
  • Advanced Algo (100 Marks)

MindTree
Implementation
Questions

Implementation Coding Ques

Mindtree Implementation Coding Questions are based on basic programming concepts such as aaray, string, functions and data types.

MindTree
DS/Algo
Questions

DS/Algo Coding Ques

Mindtree DS/Algo Coding Questions are based on data structures concepts such as sorting, searching and number theory etc. The difficulty level ques is moderate.

MindTree
Advnaced
Algo Questions

Advanced Algo Questions

MindTree Advanced Algo Questions are based on Dynamic Programming of hiher difficulty level covering concepts like minimum partion, subset sum problem etc.

MindTree Coding Test 2021

Important instructions for Mindtree Coding Test 2021-22:-

  • The program should be executed atleast once.
  • The program can be executed any number of times.
  • The execution yielding highest score is taken into consideration for the final scoring.
  • Use ‘Run custom Input‘ and/or ‘Run code‘ to debug the code by getting the output.
  • To submit the code you need to turn off the debug mode i.e. ‘Custom Input ‘.
  • You are allowed to code in
    • C
    • C++
    • Java
  • Though language are version independent if it is not explicitly specified.
TopicsNo. of Questions
Number of Questions8
Time Limit2 hrs(combined with other section)
Marking Scheme(50+75+100)
Package Offered3.5 LPA

 

MindTree Coding Questions Pattern

Mindtree Coding QuesNo of QuesDifficulty
Implementation Ques3 QuesEasy-Medium
DS/Algo Ques3 QuesMedium-Hard
Advanced Algo Ques2 QuesHard

MindTree Practice

Here, you can practice mindtree miscellaneous coding questions based on implementation, DS/Algo and Advanced Algo section that comes in exam. These are some of the common ques asked in mindtree coding test.

  1. Pattern based Programs.
  2. Remove vowel from the given String.
  3. Eliminate repeated array from the given string.
  4. Counting the number of even and odd elements in an array.
  5. Replace a sub-string in a string.
  6. Loop Based Programs.
  7. Find Prime Numbers up to n.
  8.  Reverse a String.

Question: Self Sufficient

Problem Statement – 

Abhijeet is one of those students who tries to get his own money by part time jobs in various places to fill up the expenses for buying books. He is not placed in one place, so what he does, he tries to allocate how much the book he needs will cost, and then work to earn that much money only. He works and then buys the book respectively. Sometimes he gets more money than he needs so the money is saved for the next book. Sometimes he doesn’t. In that time, if he has stored money from previous books, he can afford it, otherwise he needs money from his parents.

Now His parents go to work and he can’t contact them amid a day. You are his friend, and you have to find how much money minimum he can borrow from his parents so that he can buy all the books.

He can Buy the book in any order.

Function Description:

Complete the function with the following parameters:

NameTypeDescription
NIntegerHow many Books he has to buy that day.
EarnArray[ ]Integer arrayArray of his earnings for the ith book
CostArray[ ]Integer arrayArray of the actual cost of the ith book.

Constraints:

  • 1 <= N <= 10^3
  • 1 <= EarnArray[i] <= 10^3
  • 1 <=  CostArray[i] <= 10^3

Input Format:

  • First line contains N.
  • Second N lines contain The ith earning for the ith book.
  • After that N lines contain The cost of the ith book.

Output Format: The minimum money he needs to cover the total expense.

Sample Input 1:

3

[3 4 2]

[5 3 4]

Sample Output 1:

3

Explanation:

At first he buys the 2nd book, which costs 3 rupees, so he saves 1 rupee. Then he buys the 1st book, that takes 2 rupees more. So he spends his stored 1 rupee and hence he needs 1 rupee more. Then he buys the last book.

#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, ans =0,sum=0;
cin>>n;
vector<int> arr1(n),arr2(n);
for(int i=0;i<n;i++) cin>>arr2[i];
for(int i=0;i<n;i++) cin>>arr1[i];
for(int i=0;i<n;i++) arr2[i]-=arr1[i];

sort(arr2.begin(),arr2.end(),greater<int>());
for(int i=0;i<n;i++)
{
sum+=arr2[i];
if(sum<0)
{ans+=abs(sum);sum=0;}
}
cout<<ans;
}
n=int(input())
L1=[0] *n
L2=[0]*n
for i in range(n):
L2[i]=int(input())
for i in range(n):
L1[i]=int(input())

for i in range(n):
L2[i]=L2[i]-L1[i];

L2.sort()
su=0
ans=0
for i in range(n):
su=su+L2[i]
if su<0:
ans = ans + abs(su)
su=0

print(ans)

Question: Parallel Columbus

Problem Statement-

Nobel Prize-winning Austrian-Irish physicist Erwin Schrödinger developed a machine and brought as many Christopher Columbus from as many parallel universes he could. Actually he was quite amused by the fact that Columbus tried to find India and got America. He planned to dig it further.

Though totally for research purposes, he made a grid of size n X m, and planted some people of America in a position (x,y) [in 1 based indexing of the grid], and then planted you with some of your friends in the (n,m) position of the grid. Now he gathered all the Columbus in 1,1 positions and started a race.

Given the values for n, m, x, y, you have to tell how many different Columbus(s) together will explore you as India for the first time.

Remember, the Columbus who will reach to the people of America, will be thinking that as India and hence wont come further.

Function Description:

Complete the markgame function in the editor below. It has the following parameter(s):

Parameters:

NameTypeDescription
nInteger

The number of rows in the grid.

mIntegerThe number of columns in the grid.
xIntegerThe American cell’s Row.
yIntegerThe American cell’s Column.

Constraints:

  • 1 <= n <= 10^2
  • 1 <= m <= 10^2
  • 1 <= x <= n
  • 1 <= y <= m

Input Format:

  • The first line contains an integer, n, denoting the number of rows in the grid.
  • The next line contains an integer m, denoting the number of columns in the grid.
  • The next line contains an integer, x, denoting the American cell’s row.
  • The next line contains an integer, y, denoting the American cell’s column.

Sample Cases

Sample Input 1

2

2

2

1

Sample Output 1

1

Explanation

The only way possible is (1,1) ->(2,1) -> (2,2), so the answer is 1. 

#include <bits/stdc++.h>
using namespace std;
unordered_map<int,long long int> f;

long long int Fact(int n)
{
if(f[n]) return f[n];
return f[n]=n*Fact(n-1);
}

int main()
{
int n,m,x,y;
cin>>n>>m>>x>>y;
n-=1;m-=1;x-=1;y-=1;
f[0]=f[1]=1;
int p=(Fact(m+n)/(Fact(m)*Fact(n)));
int imp=((Fact(x+y)/(Fact(x)*Fact(y)))*(Fact(m-x+n-y)/(Fact(m-x)*Fact(n-y))));
cout<<p-imp;
}
import math
n=int(input())-1
m=int(input())-1
x=int(input())-1
y=int(input())-1

ans=math.factorial(n+m)
ans=ans//(math.factorial(n))
ans=ans//(math.factorial(m))

ans1=math.factorial(x+y)
ans1=ans1//(math.factorial(x))
ans1=ans1//(math.factorial(y))

x1=n-x
y1=m-y

ans2=math.factorial(x1+y1)
ans2=ans2//(math.factorial(x1))
ans2=ans2//(math.factorial(y1))
print(ans-(ans1*ans2))

Question: Amusement park

Problem Statement-

Aashay loves to go to WONDERLA , an amusement park. They are offering students who can code well with some discount. Our task is to reduce the cost of the ticket as low as possible.

They will give some k turns to remove the cost of one ticket where the cost of tickets are combined and given as string.Help Aashay in coding as he is not good in programming and get a 50%  discount for your ticket.

Constraints:

  • 1 <= number of tickets <= 10^5
  • 1 <= K <= number of tickets

Input Format for Custom Testing:

  • The first line contains a string,Tickets, denoting the given cost of each ticket.
  • The next line contains an integer, K, denoting the number of tickets that is to be removed.

Sample Cases:

  • Sample Input 1
    203
    3
  • Sample Output 1
    0
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int smallestNumber (string num, int k)
{
if(num.length()<=k)
return 0;
unordered_map<char,int> pos;
for(int i=0;i<num.length();i++)
{ pos[num[i]]=i;}

string temp=num;
sort(num.begin(),num.end());
string ans=num.substr(0,num.length()-k);
vector<int> v;
for(int i=0;i<ans.length();i++)
v.push_back(pos[ans[i]]);

sort(v.begin(),v.end());
string ret;
for(int i=0;i<v.size();i++)
{ret+=temp[v[i]];}
int final=stoi(ret);

return final;
}
int main()
{
string s;
cin >> s;
int k;
cin >> k;
int ans;
cout<<smallestNumber(s,k)%(int)(pow(10,9)+7);
return 0;
}
import sys
n=input()
k=int(input())
n1=len(n)
if len(n)<=k:
print(0)
sys.exit()

a=''
i=0
while i<(n1-1) and k>0:
if int(n[i])>int(n[i+1]):
i+=1
k-=1
continue

else:
a+=n[i]
i+=1

a+=n[i]
i+=1
if k>0:
a=a[:-k]

if i<=(n1-1):
while i<n1:
a+=n[i]
i+=1

print(int(a)%((10**9)+7))

Question: Airport authority

Problem Statement -:

In an airport , the Airport  authority decides to charge some minimum amount to the passengers who are carrying luggage with them. They set a threshold weight value, say T, if the luggage exceeds the weight threshold you should pay double the base amount. If it is less than or equal to threshold then you have to pay $1.  

Function Description:

Complete the weightMachine function in the editor below. It has the following parameter(s):

Parameters:

NameTypeDescription
NIntegernumber of luggage
TIntegerweight of each luggage
weights[ ]Integer arraythreshold weight

Returns: The function must return an INTEGER denoting the required amount to be paid.

Constraints:

  • 1 <= N <= 10^5
  • 1 <= weights[i] <= 10^5
  • 1 <= T <= 10^5

Input Format for Custom Testing:

  • The first line contains an integer, N, denoting the number of luggages. 
  • Each line i of the N subsequent lines (where 0 <= i <n) contains an integer describing weight of ith luggage. 
  • The next line contains an integer, T, denoting the threshold weight of the boundary wall.

Sample Cases:

  • Sample Input 1
    4
    1
    2
    3
    4
    3
  • Sample Output 1
    5
  • Explanation:
    Here all weights are less than threshold weight except the luggage with weight 4 (at index 3) so all pays base fare and it pays double fare.
def weightMachine(N,weights,T):
amount=0
for i in weights:
amount+=1
if(i>T):
amount+=1
return amount
N=int(input())
weights=[]
for i in range(N):
weights.append(int(input()))
T=int(input())
print(weightMachine(N,weights,T))
#include <stdio.h>
long int weightMachine(long int N,long int weights[],long int T)
{
long int amount=0,i;
for(i=0;i<N;i++)
{
amount++;
if(weights[i]>T)
{
amount++;
}
}
return amount;
}
int main()
{
long int N,i,T;
scanf("%ld",&N);
long int weights[N];
for(i=0;i<N;i++)
{
scanf("%ld",&weights[i]);
}
scanf("%ld",&T);
printf("%ld",weightMachine(N,weights,T));

return 0;
}