Professional Documents
Culture Documents
Mindtree Interview Ques
Mindtree Interview Ques
TR Questions:
• HTTP: HTTP stands for Hypertext Transfer Protocol. HTTP is a set of rules and standards that
regulate how information can be sent across the Internet. HTTP establishes communication
standards for web browsers and servers. HTTP is a network protocol that runs on top of TCP
at the application layer. HTTP employs hypertext structured text to create a logical link
between text-containing nodes. It's also known as the "stateless protocol" since each
command is conducted separately, without using the last run command as a reference.
• HTTPS: HTTPS is the acronym for HyperText Transfer Protocol Secure. It is a highly advanced
and secure HTTP version. For data communication, it uses port 443. Encrypting all
communication using SSL, it provides for secure transactions. It's a hybrid of the SSL/TLS and
HTTP protocols. It allows a network server to be identified in an encrypted and safe manner.
HTTPS also enables the server and browser to establish a secure encrypted connection. It
provides data security in both directions. This assists you in preventing the theft of
potentially sensitive information.
Multiprogramming Multitasking
• Abstraction: Abstraction is the technique of hiding unnecessary details and displaying only
the necessary details. The practice of identifying only the required attributes of an object
while discarding the irrelevant information is known as data abstraction. The features and
behaviours of an object assist to distinguish it from other things of the same sort, as well as
classifying and grouping them.
◦ For example, consider an ATM machine. In our daily lives, we all utilise an ATM
machine for cash withdrawals, money transfers, retrieving minimum statements, and
so on. However, we have no idea what happens inside an ATM machine when you
insert an ATM card to execute any type of transaction.
• Polymorphism: Polymorphism is the technique of using one thing in more than one form.
Polymorphism, in other terms, allows you to specify a single interface with various
implementations.
◦ For example, a person can have different relations with different people around
them. A person may be a father to a son, a brother to a sister, a son to a mother and
so on. Similarly, a person may behave differently depending on the situation. For
example, two people in an office are considered colleagues during work hours, but
they can be friends after office hours. When you're in class, you act like a student;
when you're in the store, you act like a customer; when you're at home, you act like
a son or daughter; here, one person exhibits a variety of behaviours.
Only abstract methods are allowed in an There are abstract and non-abstract
interface. It can also contain default and methods in an abstract class.
static methods with Java 8.
Only static and final variables are used in the Variables in an abstract class can be
interface. final, non-final, static, or non-static.
Only another Java interface can be extended An abstract class can implement
by an interface. numerous Java interfaces by
extending another Java class.
The keyword "implements" can be used to The keyword "extends" can be used
create an interface. to extend an abstract class.
By default, members of a Java interface are Private, protected, and other class
public. members can be found in a Java
abstract class.
6. Does Java allow a class to inherit from multiple classes? If not, how can a class achieve the
properties of more than one class (i.e., multiple inheritance)?
Multiple inheritances are not allowed by Java using classes. This is because dealing with the
complexity that multiple inheritances produce is quite difficult.
For example,
import java.io.*;
class Base1 {
void fun() {
System.out.println("Parent1");
}}
class Base2 {
void fun() {
System.out.println("Parent2");
}
}
class Child extends Base1, Base2 {
public static void main(String args[]) {
Child obj = new Child(); // object creation of the child class
obj.fun(); // it leads to compilation error since fun() is defined in both Base1 and Base2 and the
compiler gets in an ambiguous situation as to which fun() is being referred to.
}
}
In the above code, a compilation error is thrown. This is because both the classes Base1 and Base2
contain a definition for the function fun(). This confuses the compiler as to which fun() is being
referred to.
Multiple Inheritance causes issues during operations such as casting, constructor chaining, and so
on, and the main reason is that we only need multiple inheritances in a few cases, thus it's best to
leave it out to keep things simple and easy.
However, the main objective of multiple inheritances to inherit from multiple classes can be
obtained via interfaces in Java. An interface, like a class, has variables and methods, however, unlike
a class, the methods in an interface are abstract by default. The class that implements an interface
needs to define the member functions. If a class implements multiple interfaces, or if an interface
extends multiple interfaces, multiple inheritances via interface happen.
For example, the code for the above example using interfaces would be like this:
interface Base1
{
public void fun();
}
interface Base2
{
public void fun();
}
class Child implements Interface1, Interface2
{
public void fun()
{
System.out.println("Implementing the fun() of the interface.");
}
public static void main(String args[]){
Child obj = new Child();
obj.fun();
}}
In the above code, the fun() is not defined in the interfaces Base1 and Base2. They are defined by
the classes which implement the interfaces. This leads to no ambiguity and the purpose of multiple
inheritances has been solved.
7. Write a program to calculate the Least Common Multiple (LCM) of two numbers.
Example : Input : a = 10, b =15 Output : 30 a = 5, b = 7 Output : 35
Input :
a = 10, b =15
Output :
30
a = 5, b = 7
Output :
35
Approach:
Let us assume the two numbers are a and b. Then, the two numbers have the following
relationship :
a * b = LCM(a, b) * GCD(a, b)
or,
LCM(a, b) = (a * b) / GCD(a, b)
Let us take an example to understand better. For a = 10 and b = 15, a * b = 150, LCM(10, 15) = 30,
GCD(10, 15) = 5. So, a * b = LCM(a, b) * GCD(a, b).
Code :
#include <iostream>
using namespace std;
//Function to find the greatest common divisor of the two numbers
int findGCD(int a,int b)
{
if (b == 0)
return a;
return findGCD(b, a % b);
}
// Function to return LCM of two numbers
int findLCM(int a, int b)
{
return (a * b) / findGCD(a, b);
}
int main()
{
int a = 10, b = 15;
cout <<"The Least Common Multiple of the two numbers " << a << " and " << b << " is : " <<
findLCM(a, b);
return 0;
}
Output:
The Least Common Multiple of the two numbers 10 and 15 is : 30
Explanation:
In the above code, the function findGCD() finds the greatest common divisor of the two numbers a
and b. We use the Euclidean algorithm to find the greatest common divisor of the two numbers.
The function findLCM() finds the least common multiple of the two numbers.
8. Write a program to sort a given array of numbers. The sorting algorithm should give best
performance in every case (best, worst and average). Example : Input : arr = {3, 5, 7, 1, 2, 4, 6}
Output : {1, 2, 3, 4, 5, 6, 7}
Example:
Input :
arr = {3, 5, 7, 1, 2, 4, 6}
Output :
{1, 2, 3, 4, 5, 6, 7}
Approach:
Since we want the sorting algorithm to give the best time complexity in all three cases (that is,
best, worst and average), we will implement merge sort to sort the given array of numbers. In
merge sort, we divide an array into two halves recursively, sort each half and then merge them.
Code:
#include<bits/stdc++.h>
using namespace std;
//function to merge the two sorted halves of the array
void merge(int *arr, int start, int mid, int end) {
int temp[end - start + 1];// creating a temporary array to store the sorted array
int i = start;
int j = mid+1;
int k = 0;
while(i <= mid && j <= end) {
if(arr[i] <= arr[j]) {
temp[k] = arr[i];
i = i + 1;
}
else {
temp[k] = arr[j];
j = j + 1;
}
k = k + 1;
}
//If the first half still has elements, we add them to the temporary array
while(i <= mid) {
temp[k ++] = arr[i ++];
}
//If the second half still has elements, we add them to the temporary array
while(j <= end) {
temp[k ++] = arr[j ++];
}
// We store the sorted order of elements in the original array
for(i = start; i <= end; i ++) {
arr[i] = temp[i - start]
}
}
// function to sort an array of elements
void mergeSort(int *arr, int start, int end) {
We can eat a total of 22 chocolates for Rs. 15. First, we will buy 15 chocolates for 15 rupees since
each chocolate costs Re. 1. Now, we have 15 wrappers. We return all the 15 wrappers to the
shopkeeper which gives us 5 chocolates (15 / 3 = 5). We eat those five chocolates and return 3
wrappers to the shopkeeper and get 1 chocolate. We eat that chocolate and again give 3 wrappers
which give us one chocolate. So, in total, we can have 15 + 5 + 1 + 1 chocolates.
10. What do you understand by super key, candidate key, primary key and foreign key in the
context of database management systems?
• Super key: Super Key is a set of attributes that can be used to uniquely identify a tuple. The
super key is created by adding zero or more attributes to the candidate key. A candidate key
is a super key, but not the other way around.
• Candidate key: A candidate key is the smallest set of attributes that can uniquely identify a
tuple. For each tuple, the Candidate Key value is unique and non-null. In relation, there can
be more than one candidate key. The candidate key might be simple (only having one
attribute) or composite (containing multiple attributes).
• Primary key: In relation, there may be more than one candidate key, with one being chosen
as the primary key. This primary key is chosen by the database administrator based on the
requirements amongst the candidate keys.
• Foreign key: A foreign key is a column or set of columns in a relational database table that
connects data from two other tables. It serves as a cross-reference between tables by
referencing the primary key of another table and therefore creating a relationship between
them.
Department :
department_id (primary key), department_name
Here, for the Teacher table, the following are the different types of keys present :
• The candidate keys can be teacher_id, teacher_phone_number and teacher_aadhar since
they all can uniquely identify a record of the table.
• Out of the above three candidate keys, any one of them can be chosen as the primary key.
We generally choose teacher_id as the primary key.
• Any of the above candidate keys when grouped with any other key form the super key. For
example, teacher_id, teacher_name can together form a super key.
• Teacher_department_id is a foreign key for the Teacher table since it is a
• primary key in the Department table and it links the two tables.
11. What are the different types of SQL commands?
Delete Truncate
The DELETE command is used This command is used to delete all of the rows in a
to remove specific rows from table.
a table (one or more).
In order to filter the records, The TRUNCATE command may not use a WHERE
the DELETE command may clause.
include a WHERE clause.
A tuple is locked before being Before removing the table data, the data page is
deleted with the DELETE locked in this command.
statement.
DELETE permission on the To use Truncate on a table, the table must have at
table is required to use least ALTER permission.
Delete.
The DELETE command is more The TRUNCATE command, on the other hand, is
time consuming than the faster than the DELETE command.
TRUNCATE command.
new malloc()
When we use a new operator, it Usage of the malloc() function does not involve
calls the constructor. invoking constructors.
It returns the data type specified It returns a void * type which needs to be
while using the new operator. typecasted manually to the required data type.
When the new operator fails, it When the malloc() command fails, it returns
throws an error of bad_alloc NULL.
exception.
Here, the size of memory Here, the size of memory required needs to be
required is computed computed manually and provided at the time of
automatically by the compiler. using malloc().
14. Explain the Open Systems Interconnection (OSI) model in the context of computer networks.
Following are the different layers in the OSI model:
Physical Layer: The physical layer is the lowest layer in the OSI reference model. It is in charge of
establishing a physical connection between the devices. Bits of information are stored in the
physical layer. Following are the responsibilities of the physical layer :
• Bit synchronisation: A clock is provided by the physical layer, which allows the bits to be
synchronised. This clock controls both the sender and the receiver, ensuring bit-level
synchronisation.
• The transmission rate, or the number of bits transferred per second, is likewise defined by
the Physical layer.
• Physical topologies: The physical layer defines the arrangement of devices/nodes in a
network, such as bus, star, or mesh topologies.
• Transmission mode: The physical layer also specifies how data is passed between the two
linked devices. Simplex, half-duplex, and full-duplex transmission modes are available.
Data Link Layer (DLL): The data link layer is in charge of message transport from node to node. The
major purpose of this layer is to ensure that data transfers from one node to another through the
physical layer are error-free. Following are the responsibilities of data link layer :
• Framing: The data link layer is responsible for framing. It allows a sender to deliver a set of
bits to a receiver that are relevant to the receiver. This can be done by attaching unique bit
patterns to the frame's beginning and end.
• Physical addressing: After producing frames, the Data link layer adds the sender and/or
receiver's physical addresses (MAC addresses) to the header of each frame.
• Error control: The data link layer implements error control by detecting and retransmitting
broken or lost frames.
• Flow Control: Because the data rate on both sides must be consistent or the data would be
corrupted, flow control coordinates the amount of data that can be transferred before
acknowledgment.
• When many devices share a single communication channel, the MAC sub-layer of the data
link layer assists in determining which device has control over the channel at any particular
time.
Network Layer: The network layer is responsible for data transmission between hosts on different
networks. Following are the responsibilities of the network layer :
• Routing: From source to destination, the network layer protocols determine which path is
best. Routing is the name for this network layer function.
• The network layer defines an addressing scheme in order to uniquely identify each device
on the internetwork. The network layer places the IP addresses of the sender and receiver
in the header. An address like this recognises each gadget in a unique and universal way.
Transport Layer: The transport layer delivers services to the application layer while also receiving
services from the network layer. Segments are the units of data in the transport layer. Following are
the responsibilities of the Transport layer :
• This layer accepts the message from the (session) layer and splits it down into smaller parts.
A header is attached to each of the segments created. The message is reassembled by the
transport layer at the destination station.
• The transport layer header provides a form of address called service point address or port
address in order to deliver the message to the relevant process. The transport layer ensures
that the message is delivered to the relevant process by supplying this address.
Session Layer: The Session Layer is in charge of establishing connections, maintaining sessions,
authenticating users, and ensuring security. Following are the responsibilities of session layer :
• Establishing, maintaining, and terminating a session: The layer enables the two processes to
create, use, and terminate a connection.
• Synchronization: This layer allows a process to insert checkpoints into the data that serve as
synchronisation points. These synchronisation points aid in the detection of errors so that
data may be correctly resynchronized, message ends are not severed prematurely, and data
loss is avoided.
• Dialog Controller: The session layer enables two systems to communicate in half-duplex or
full-duplex mode.
Presentation Layer: The Presentation Layer is often referred to as the Translation Layer. The data
from the application layer is retrieved and processed here so that it may be transmitted across the
network in the proper format. Following are the responsibilities of the presentation layer :
• It is responsible for translations such as ASCII to EBCDIC.
• Encryption/decryption: Data encryption is the process of converting data into a different
form or coding. The ciphertext is the encrypted data, and the plain text is the decoded data.
When encrypting and decrypting data, a key-value is used.
• Compression: This technique reduces the amount of data that must be transmitted over the
network.
Application Layer: The Application layer, which is implemented by network applications, is at the
very top of the OSI Reference Model stack of levels. Following are the responsibilities of the
application layer :
• This layer also acts as a window for application services to connect to the network and show
the information they receive to the user.
• It is also responsible for file transfer access and management.
• It is responsible for mail services.
• It is also responsible for directory services.
15. Differentiate between WHERE clause and HAVING clause in SQL.
The following table lists the differences between the WHERE clause and the HAVING clause:
WHERE HAVING
The WHERE Clause is used to filter records The HAVING Clause is used to filter
from a table depending on a condition records from groups based on a
that is given. condition that is given.
You can use the WHERE Clause without The HAVING Clause is ineffective
the GROUP BY Clause. without the GROUP BY Clause.
The WHERE clause can be used in Only the SELECT statement can employ
conjunction with the SELECT, UPDATE, and the HAVING Clause.
DELETE statements.
With single-row functions such as UPPER, With multiple-row functions like SUM,
LOWER, and so on, the WHERE Clause is COUNT, and others, the HAVING
used. Clause is employed.
The WHERE Clause comes before the After the GROUP BY Clause, the
GROUP BY Clause. HAVING Clause is used.
16. Write a query in SQL to find the details of an employee having the nth highest salary from a
given table Employee. The value of n needs to be taken as user input. Assume that the table
Employee has the following schema.
name - denoting the name of the employee
salary - denoting the salary of the employee
Approach:
We use the dense_rank() function to display the details of the employee having the nth highest
salary. The function DENSE_RANK returns the rank of a row in an ordered collection of rows as a
NUMBER. The ranks are in ascending order, starting with 1. Based on the values of the value exprs
in the order by clause, DENSE RANK computes the rank of each row returned from a query in relation
to the other rows as an analytic function.
Query:
select name, salary from(
select name, salary, dense_rank()
over(order by salary desc)input from Employee)
where input = &n;
Explanation:
In the above query, we first sort the data according to the descending order of the salary and assign
a rank to each of the employees starting from 1. In case of an event where the salary of two
employees is the same, they both are assigned the same rank. Then we display the data whose rank
is equal to the given input.
SQL databases have fixed and NoSQL databases can have dynamic schema.
static predefined schema.
SQL databases are vertically NoSQL databases, on the other hand, are
scalable in almost all cases. horizontally scalable. By sharding, or adding
This means that by boosting multiple servers to your NoSQL database, you can
RAM, CPU, or SSD, you may handle greater traffic. It's the difference between
increase the demand on a adding more storeys to a single building and
single server. adding more buildings to a neighbourhood. NoSQL
databases can grow in size and power, making
them the best solution for huge or constantly
changing data sets.
Approach:
We use two pointers to explore both the array and the subarray. We maintain the pointer of array
arr2[] and increase the pointer of both arrays if any element of arr1[] matches the first element of
arr2[], otherwise set the pointer of arr1 to the next element of the previous starting point and reset
the pointer of arr2 to 0. If all of arr2's elements match, print True; otherwise, print False.
The following is how the above strategy is put into action:
Code:
#include <bits/stdc++.h>
using namespace std;
//function to check if the second array is a subarray of the first array
bool checkSubArray(int arr1[], int arr2[], int n, int m)
{
int i = 0, j = 0;
while (i < n && j < m) {
// If element matches
// increment both pointers
if (arr1[i] == arr2[j]) {
i++;
j++;
else {
i = i - j + 1;// setting the pointer of the first array to the next element of the previous starting
point
j = 0; // resetting the pointer of the second array to 0.
}
}
return false;
}
int main()
{
int arr1[] = { 2, 3, 0, 5, 1, 1, 2 };
int arr2[] = { 3, 0, 5, 1 };
int n = sizeof(arr1) / sizeof(arr1[0]);
int m = sizeof(arr2) / sizeof(arr2[0]);
bool res = checkSubArray(arr1, arr2, n, m);
if (res)
cout << "True\n";
else
cout << "False\n";
return 0;
}
Explanation:
In the above code, the function checkSubArray checks whether the second array is a sub array of
the first array or not and returns the output correspondingly. We maintain two pointers, one for the
first array and the other for the second array. If the elements match, we increment both the
pointers; otherwise, we reset the pointers.
22. Given a string as an input, write a program to reverse the words in the given string and display
the new string.
Example:
Input:
str = “Talentio Academy”
Output :
Academy Talentio
Approach:
We maintain a vector of strings. We traverse the given string and keep forming the word until a
space is encountered. When space is encountered we add the word formed to the vector of strings.
In the end, we print the vector of strings in reverse format.
Code :
#include <bits/stdc++.h>
using namespace std;
// function to reverse the words in an inputted string
void displayModifiedString(string str)
{
// vector to store all the words of the inputted string
vector<string> arr;
string temp = ""; // variable to form each word of the string
for (int i = 0; i < str.length(); i++)
{
Output :
best is talentio
Explanation :
In the above code, the function displayModifiedString takes a string input and displays the modified
string with words in reverse order. We keep forming a word until a space character is found. Once
space is found, we push back the word to the vector. Lastly, we display the vector in reverse order.
HR Question :
1. Tell me about yourself in a few words.
2. Would you consider relocating to another part of India?
3. What do you hope to get out of this job?
4. What drew you to MindTree in the first place?
5. In five years, where do you see yourself?
6. Tell me about your internships and projects.
7. What prompted you to look for a new job? (Many seasoned professionals on the lookout for a
new job ask this question.)
8. Tell me about a moment when you faced a challenge and how you dealt with it.
9. Let's pretend you're in charge of a group. One of your team members is underperforming and,
despite many warnings, refuses to modify his or her attitude. What will you do if you find yourself
in this situation?
10. Describe a circumstance in which you tried your hardest but failed.