0% found this document useful (0 votes)
75 views46 pages

Mindtree Final Material

Uploaded by

SBV FOR WORLD
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views46 pages

Mindtree Final Material

Uploaded by

SBV FOR WORLD
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

PLACEMENT

PREPARATION

youtube.com/@teknouf
ubk anna
CODING
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.

UF
You can find these questions screenshots at previous year paper
folder
Pattern based Programs.
Remove vowel from the given String.
Eliminate repeated array from the given string.
Counting the number of even and odd elements in an array.
Replace a sub-string in a string.
Loop Based Programs.
O
Find Prime Numbers up to n.
Reverse a String.
KN
TE

youtube.com/@teknouf
ubk anna
CODING
Dani has N cups that needs to be filed with soda and each cup
has a different capacity of soda that it can hold.
Dani has a particular method of filing the cups. He chooses a
certain amount, say M, and fills all the cups with M litters of
soda. if the cup's capacity is less than M, the extra soda
overflows and splatters the ground.
It is given that Dani wants the sum of the soda that is held in the

UF
cups to be at least L. He also wants the least amount of soda to
be wasted.
Your task is to tell Dani the smallest value of M that allows him
to meet the conditions given above,,if no value of M that allows
him to meet the condition, cutput -1.
Function Description
Complete the cups function in the editor below.
O
The function must return an INTEGER denoting the The smallest
value of M that Dani should choose such that amount of soda in
KN

the
cups is at least L. and - 1 il he can't choose such M.,

5
2
3
TE

4
5
6
15

OP:
4

youtube.com/@teknouf
ubk anna
def cups(N, capacities, L):
max_capacity = max(capacities)

left, right = 0, max_capacity


result = -1

while left <= right:


mid = (left + right) // 2

UF
total_soda = sum(min(mid, capacity) for capacity in
capacities)

if total_soda >= L:
result = mid
right = mid - 1
else:
left = mid + 1
O
return result

N = int(input())
KN

capacities = [int(input()) for _ in range(N)]


L = int(input())

print(cups(N, capacities, L))


TE

youtube.com/@teknouf
ubk anna
import java.util.Scanner;

public class Main {

public static int cups(int N, int[] capacities, int L) {


int maxCapacity = 0;
for (int capacity : capacities) {
maxCapacity = Math.max(maxCapacity, capacity);
}

UF
int left = 0, right = maxCapacity;
int result = -1;

while (left <= right) {


int mid = (left + right) / 2;
int totalSoda = 0;
for (int capacity : capacities) {
totalSoda += Math.min(mid, capacity);
}
O
if (totalSoda >= L) {
result = mid;
right = mid - 1;
} else {
left = mid + 1;
KN

}
}

return result;
}

public static void main(String[] args) {


Scanner sc = new Scanner(System.in);
TE

int N = sc.nextInt();
int[] capacities = new int[N];

for (int i = 0; i < N; i++) {


capacities[i] = sc.nextInt();
}

int L = sc.nextInt();

System.out.println(cups(N, capacities, L));


}
}

youtube.com/@teknouf
ubk anna
CODING
There are N cloud servers, each having & value indicating their
usage. You are asked to perform the operation described below
on these server
In a single operation, you can start more tasks in the lost busy
server (any of them in case of to). This will increase the chosen
server's usage value by 1.

UF
You know your manager is coming over soon to review the cloud
server usage. it is also guaranteed that he will only be
concerned with the K-th smallest usage value among the
cloud servers. You only have the time for M operations before
your manager arrives.
Your task is to find the largest possible value for the K-th
smallest usage in the given scenario.
O
N=5
usages = [1, 2, 3, 4, 5]
K=3
KN

M=3

O/P:
3
TE

youtube.com/@teknouf
ubk anna
CODING
def max_kth_smallest_usage(N, usages, K, M):
usages.sort()

for _ in range(M):
usages[0] += 1

UF
i=0
while i < N - 1 and usages[i] > usages[i + 1]:
usages[i], usages[i + 1] = usages[i + 1], usages[i]
i += 1

return usages[K - 1]

N=5
O
usages = [1, 2, 3, 4, 5]
K=3
M=3
KN

print(max_kth_smallest_usage(N, usages, K, M))


TE

youtube.com/@teknouf
ubk anna
CODING
import java.util.Arrays;

public class Main {

public static int maxKthSmallestUsage(int N, int[] usages, int

UF
K, int M) {
Arrays.sort(usages);

for (int i = 0; i < M; i++) {


usages[0]++;
int j = 0;
while (j < N - 1 && usages[j] > usages[j + 1]) {
int temp = usages[j];
usages[j] = usages[j + 1];
O
usages[j + 1] = temp;
j++;
}
KN

return usages[K - 1];


}

public static void main(String[] args) {


int N = 5;
TE

int[] usages = {1, 2, 3, 4, 5};


int K = 3;
int M = 3;

System.out.println(maxKthSmallestUsage(N, usages, K,
M));
}
}

youtube.com/@teknouf
ubk anna
CODING
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

UF
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.
O
He can Buy the book in any order.

Function Description:
KN

Complete the function with the following parameters:

Name Type Description


TE

How many Books he has to


N Integer
buy that day.

Array of his earnings for the


EarnArray[ ] Integer array
ith book

Array of the actual cost of


CostArray[ ] Integer array
the ith book.

youtube.com/@teknouf
ubk anna
CODING
Constraints:

1 <= N <= 10^3


1 <= EarnArray[i] <= 10^3
1 <= CostArray[i] <= 10^3
Input Format:

UF
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:
O
3

[3 4 2]
KN

[5 3 4]

Sample Output 1:

3
TE

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.

youtube.com/@teknouf
ubk anna
CODING
n=int(input())
L1=[0] *n
L2=[0]*n
for i in range(n):
L2[i]=int(input())
for i in range(n):

UF
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]
O
if su<0:
ans = ans + abs(su)
su=0
print(ans)
KN
TE

youtube.com/@teknouf
ubk anna
CODING
import java.util.Scanner;
import java.util.Arrays;

public class Main {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

UF
int n = sc.nextInt();
int[] L1 = new int[n];
int[] L2 = new int[n];

for (int i = 0; i < n; i++) {


L2[i] = sc.nextInt();
}
for (int i = 0; i < n; i++) {
L1[i] = sc.nextInt();
}
O
for (int i = 0; i < n; i++) {
L2[i] = L2[i] - L1[i];
Arrays.sort(L2);
}
KN

int su = 0;
int ans = 0;

for (int i = 0; i < n; i++) {


su = su + L2[i];
if (su < 0) {
ans = ans + Math.abs(su);
TE

su = 0;
}
}

System.out.println(ans);

sc.close();
}
}

youtube.com/@teknouf
ubk anna
CODING
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.

UF
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
O
first time.

Remember, the Columbus who will reach to the people of


America, will be thinking that as India and hence wont come
KN

further.

Function Description:

Complete the markgame function in the editor below. It has the


following parameter(s):
TE

Name Type Description

n Integer The number of rows in the grid.

m Integer The number of columns in the grid.

x Integer The American cell’s Row.

y Integer The American cell’s Column.

youtube.com/@teknouf
ubk anna
CODING
Constraints:

1 <= n <= 10^2


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

UF
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.
O
The next line contains an integer, y, denoting the American cell’s
column.
Sample Cases
KN

Sample Input 1

2
TE

Sample Output 1

Explanation

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

youtube.com/@teknouf
ubk anna
CODING
import math
n=int(input())-1
m=int(input())-1
x=int(input())-1
y=int(input())-1

UF
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
O
ans2=math.factorial(x1+y1)
ans2=ans2//(math.factorial(x1))
ans2=ans2//(math.factorial(y1))
print(ans-(ans1*ans2))
KN
TE

youtube.com/@teknouf
ubk anna
CODING
import java.util.Scanner;

public class Main {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

UF
int n = sc.nextInt() - 1;
int m = sc.nextInt() - 1;
int x = sc.nextInt() - 1;
int y = sc.nextInt() - 1;

long ans = factorial(n + m) / (factorial(n) * factorial(m));


long ans1 = factorial(x + y) / (factorial(x) * factorial(y));
int x1 = n - x;
O
int y1 = m - y;
long ans2 = factorial(x1 + y1) / (factorial(x1) * factorial(y1));

System.out.println(ans - (ans1 * ans2));


KN

sc.close();
}

public static long factorial(int num) {


long result = 1;
TE

for (int i = 1; i <= num; i++) {


result *= i;
}
return result;
}
}

youtube.com/@teknouf
ubk anna
CODING
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

UF
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
O
Input Format for Custom Testing:

The first line contains a string,Tickets, denoting the given cost


of each ticket.
KN

The next line contains an integer, K, denoting the number of


tickets that is to be removed.
Sample Cases:

Sample Input 1
203
TE

3
Sample Output 1
0

youtube.com/@teknouf
ubk anna
CODING
import sys

n = input()
k = int(input())
n1 = len(n)

UF
if len(n) <= k:
print(0)
sys.exit()

a = ''
i=0

while i < (n1 - 1) and k > 0:


O
if int(n[i]) > int(n[i + 1]):
i += 1
k -= 1
continue
KN

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

a += n[i]
i += 1
TE

if k > 0:
a = a[:-k]

if i <= (n1 - 1):


while i < n1:
a += n[i]
i += 1

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

youtube.com/@teknouf
ubk anna
CODING
import java.util.Scanner;
import java.util.Stack;

public class Main {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

String n = sc.nextLine();
int k = Integer.parseInt(sc.nextLine());

UF
int n1 = n.length();

if (n1 <= k) {
System.out.println(0);
return;
}

StringBuilder a = new StringBuilder();


int i = 0;

Stack<Character> stack = new Stack<>();


O
while (i < n1) {
while (k > 0 && !stack.isEmpty() && stack.peek() > n.charAt(i)) {
stack.pop();
k--;
}
KN

stack.push(n.charAt(i));
i++;
}

while (k > 0) {
stack.pop();
k--;
}
TE

while (!stack.isEmpty()) {
a.insert(0, stack.pop());
}

if (a.length() == 0) {
System.out.println(0);
} else {
long result = Long.parseLong(a.toString()) % ((long)
Math.pow(10, 9) + 7);
System.out.println(result);
}

sc.close();
}
}

youtube.com/@teknouf
ubk anna
CODING
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.

UF
Function Description:

Complete the weightMachine function in the editor below. It has


the following parameter(s):

Name Type Description


O
N Integer number of luggage
KN

T Integer weight of each luggage

weights[ ] Integer array threshold weight


TE

youtube.com/@teknouf
ubk anna
CODING
Returns: The function must return an INTEGER denoting the
required amount to be paid.

Constraints:

1 <= N <= 10^5

UF
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.
O
The next line contains an integer, T, denoting the threshold
weight of the boundary wall.
Sample Cases:
KN

Sample Input 1
4
1
2
3
4
3
TE

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.

youtube.com/@teknouf
ubk anna
CODING
def weightMachine(N,weights,T):
amount=0
for i in weights:
amount+=1
if(i>T):
amount+=1

UF
return amount
N=int(input())
weights=[]
for i in range(N):
weights.append(int(input()))
T=int(input())
print(weightMachine(N,weights,T))
O
KN
TE

youtube.com/@teknouf
ubk anna
CODING
import java.util.Scanner;

public class Main {

public static int weightMachine(int N, int[] weights, int T) {


int amount = 0;

UF
for (int i = 0; i < N; i++) {
amount += 1;
if (weights[i] > T) {
amount += 1;
}
}
return amount;
}
O
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
KN

int N = sc.nextInt();
int[] weights = new int[N];

for (int i = 0; i < N; i++) {


weights[i] = sc.nextInt();
}
TE

int T = sc.nextInt();

System.out.println(weightMachine(N, weights, T));

sc.close();
}
}

youtube.com/@teknouf
ubk anna
CODING
Write a program to find the average of the first P multiples of an
integer N.

For example, refer to the sample cases given below

UF
Function Description

Complete the average function in the editor below. It has the


following parameter(s):
O
KN

Constraints

1 < N < 30
TE

1 < P < 10

Input Format For Custom Testing

The first line contains an integer, N, denoting the integer.

The next line contains an integer, P, denoting the number of


multiples to consider.

youtube.com/@teknouf
ubk anna
CODING

UF
O
KN
TE

youtube.com/@teknouf
ubk anna
CODING
def average():
sum=0
n=int(input())
p=int(input())

UF
for i in range(n,(n*p+1),n):
sum=sum+i
return int(sum/p)
print(average())
O
KN
TE

youtube.com/@teknouf
ubk anna
CODING
import java.util.Scanner;

public class Main {

public static int average() {

UF
Scanner sc = new Scanner(System.in);
int sum = 0;

int n = sc.nextInt();
int p = sc.nextInt();

for (int i = n; i <= n * p; i += n) {


O
sum += i;
}
KN

return sum / p;
}

public static void main(String[] args) {


System.out.println(average());
}
TE

youtube.com/@teknouf
ubk anna
CODING
Write a program to reverse the characters in the individual strings

Function Description

UF
Complete the reverseString function. It has the following
parameter(s):
O
Constraints
KN

•1 < len(stringValue) < 10^5

Input Format For Custom Testing


TE

The first line contains a string, stringValue, denoting the reversed


string

youtube.com/@teknouf
ubk anna
CODING

UF
O
KN
TE

youtube.com/@teknouf
ubk anna
CODING
def reverseWord():
List = list(input().split(" "))
updatedList= [x[::-1] for x in List]
return str(' '.join(updatedList))

UF
print(reverseWord())
O
KN
TE

youtube.com/@teknouf
ubk anna
CODING
import java.util.Scanner;

public class Main {

public static String reverseWord() {


Scanner sc = new Scanner(System.in);

UF
String input = sc.nextLine();
String[] words = input.split(" ");
StringBuilder result = new StringBuilder();

for (String word : words) {


result.append(new
StringBuilder(word).reverse().toString()).append(" ");
}
O
return result.toString().trim();
}
KN

public static void main(String[] args) {


System.out.println(reverseWord());
}
}
TE

youtube.com/@teknouf
ubk anna
CODING
You are given a function that takes an integer N. Write a
program that returns the sum of all the even numbers which are
less than or equal to N.

UF
For examples, refer to the sample cases given below.
O
KN

Function Description

Complete the sumEven function. It has the following parameter(s):


TE

youtube.com/@teknouf
ubk anna
CODING
def sumEven():
num=int(input())
sum=0
for i in range(0,num+1,2):
sum+=i

UF
return sum
print(sumEven())
O
KN
TE

youtube.com/@teknouf
ubk anna
CODING
import java.util.Scanner;

public class Main {

public static int sumEven() {

UF
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int sum = 0;

for (int i = 0; i <= num; i += 2) {


sum += i;
}
O
return sum;
}

public static void main(String[] args) {


KN

System.out.println(sumEven());
}
}
TE

youtube.com/@teknouf
ubk anna
CODING
You are given an integer array containing the IDs of a product.
Write a program to calculate the number of repetitions of the given
ID in the array and return the count.

For examples, refer to the sample cases given below.

UF
Sample Cases:
O
KN
TE

Function Description

Complete the getCount function in the editor below. It has the


following parameter(s):

youtube.com/@teknouf
ubk anna
CODING

Constraints

•1 < n < 10^5


UF
O
•1 < arr[i] < 10^5

•1 < id < 10^5


KN

Input Format For Custom Testing:

The first line contains an integer, n, denoting the number of


elements in arr.
TE

Each line i of the n subsequent lines (where 0 < i < n) contains an


integer describing the ids in the array.

The next line contains an integer, id, denoting the id to be found.

youtube.com/@teknouf
ubk anna
CODING
def getCount():
l=[]
size=int(input())
for i in range(size):

UF
c=int(input())
l.append(c)
ID=int(input())
return l.count(ID)
print(getCount())
O
KN
TE

youtube.com/@teknouf
ubk anna
CODING
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

public static int getCount() {

UF
Scanner sc = new Scanner(System.in);
ArrayList<Integer> list = new ArrayList<>();
int size = sc.nextInt();

for (int i = 0; i < size; i++) {


int c = sc.nextInt();
list.add(c);
}
O
int ID = sc.nextInt();
int count = 0;
KN

for (int num : list) {


if (num == ID) {
count++;
}
}

return count;
TE

public static void main(String[] args) {


System.out.println(getCount());
}
}

youtube.com/@teknouf
ubk anna
CODING
Write a program to calculate the number of vowels present in the
string

UF
Function Description

Complete the vowels function in the editor below. It has the


following parameter(s):
O
KN

Constraints

•1 < len(s) < 500


TE

Input Format For Custom Testing

The first line contains a string s, denoting the input string.

youtube.com/@teknouf
ubk anna
CODING

UF
O
KN
TE

youtube.com/@teknouf
ubk anna
CODING
def vowels():
count=0
s=input()
for i in s:

UF
if i in 'aeiou':
count+=1
return count
print(vowels())
O
KN
TE

youtube.com/@teknouf
ubk anna
CODING
import java.util.Scanner;

public class Main {

public static int vowels() {


Scanner sc = new Scanner(System.in);

UF
String s = sc.nextLine();
int count = 0;

for (char c : s.toCharArray()) {


if ("aeiou".indexOf(c) != -1) {
count++;
}
}
O
return count;
}
KN

public static void main(String[] args) {


System.out.println(vowels());
}
}
TE

youtube.com/@teknouf
ubk anna
Practice

Quants, Verbal & Logical

UF
O
KN

Coding Questions
TE

Technical Questions

youtube.com/@teknouf
ubk anna
INTERVIEW
EXPERIENCE

UF
O
KN
TE

youtube.com/@teknouf
ubk anna
MOCK TESTS

UF
O
KN
TE

youtube.com/@teknouf
ubk anna
AFFORDABLE PLACEMENT MATERIALS

UF
O
69 X 6 = 414/- PAY ONLY
KN

249/-

TO GET 👆🏽
DM - 👇🏽
TE

INSTAGRAM.COM/TEKNO.UF

2025
youtube.com/@teknouf
ubk anna

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy