[go: up one dir, main page]

0% found this document useful (0 votes)
26 views12 pages

MQP 01 With Solution

Model qp with solution on this subject

Uploaded by

Kamal Raj
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)
26 views12 pages

MQP 01 With Solution

Model qp with solution on this subject

Uploaded by

Kamal Raj
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/ 12

Model question paper - TIE ITCS Placement prep test

DSA/Technical round - 50M

Instructions:

● Answer all questions.


● You may use any programming language of your choice.
● You may use built-in libraries for standard data structures and algorithms.
● Partial credit may be awarded for incomplete solutions.
● Refer to sample solutions with explanation- after the questions (Note that this is how we
expect the answers from you)

Q1. (10 Marks)

Scenario: You are given a sorted array of integers.

Task: Write a function to search for a target value in the array using binary search. If the target is found,
return its index. Otherwise, return -1.

Example:

Python

array = [1, 2, 3, 4, 5, 6]
target = 4

# Output: 3

Q2. (10 Marks)

Scenario: You are given a string.

Task: Write a function to determine if the string has all unique characters.

Example:
Python

string1 = "abcdefg"
string2 = "hello"

# Output:
# string1 has all unique characters.
# string2 does not have all unique characters.

Q3. (10 Marks)

Scenario: You are given a singly linked list.

Task: Write a function to reverse the linked list.

Example:

Python

# Input linked list: 1 -> 2 -> 3 -> 4 -> 5

# Output linked list: 5 -> 4 -> 3 -> 2 -> 1

Q4. (10 Marks)

Scenario: You are given an array of integers representing the heights of buildings in a city skyline.

Task: Write a function to calculate the total area of the skyline.

Example:

Python

heights = [2, 1, 5, 6, 2, 3]

# Output: 17

Q5. (10 Marks)


Scenario: You are given a 2D grid of integers representing a map of a treasure island. '0' represents water,
and '1' represents land. You are initially positioned at the top-left corner of the grid (grid[0][0]).

Task: Write a function to find the shortest path from your initial position to the treasure, which is located
at the bottom-right corner of the grid (grid[m-1][n-1]). You can only move horizontally or vertically (not
diagonally). If there is no path to the treasure, return -1.

Example:

Python

grid = [
['1', '0', '1', '1'],
['1', '0', '1', '0'],
['1', '1', '1', '1']
]

# Output: 6

Solutions for DSA Questions Q1 to Q5 - using ALS(approach-logic-solution)


standard approach as per the Evaluating Scheme of ALS

Q1. Binary Search in a Sorted Array


● Approach: Imagine you have a dictionary and you want to find a word. You don't start from the
beginning and go word by word. You open the dictionary somewhere in the middle and see if the word
you're looking for comes before or after the page you opened. Binary search is similar!
● Logic:
1. Find the middle element of the sorted array.
2. If the middle element is the target, you found it!
3. If the target is smaller than the middle element, search in the left half of the array.
4. If the target is larger than the middle element, search in the right half of the array.
5. Keep repeating steps 1-4 until you find the target or there's no more array left to search.
● Solution:

Python

def binary_search(array, target):


"""
Searches for a target value in a sorted array using binary search.
Args:
array: The sorted array to search.
target: The target value to search for.

Returns:
The index of the target value if found, or -1 otherwise.
"""

low = 0
high = len(array) - 1

while low <= high:


mid = (low + high) // 2
if array[mid] == target:
return mid
elif array[mid] < target:
low = mid + 1
else:
high = mid - 1

return -1

Q2. Unique Characters in a String

● Approach: Think of it like checking a group of people to see if they all have different names. You'd
probably go person by person and make sure you haven't heard that name before.
● Logic:
1. Create a way to remember the characters you've seen (like a checklist).
2. Go through each character in the string, one by one.
3. If you see a character that's already on your checklist, the string doesn't have all unique characters.
4. If you get through the whole string without finding any duplicates, then all the characters are
unique.
● Solution:

Python

def has_all_unique_chars(string):
"""
Determines if a string has all unique characters.

Args:
string: The string to check.
Returns:
True if the string has all unique characters, False otherwise.
"""

seen_chars = set() # Our checklist


for char in string:
if char in seen_chars:
return False # Found a duplicate
seen_chars.add(char)
return True # No duplicates found

Q3. Reversing a Linked List

● Approach: Imagine a train with cars linked together. To reverse it, you'd detach the cars one by one
and re-attach them in the opposite order.
● Logic:
1. You need to keep track of three things: the current car (node), the one before it (previous), and the
one after it (next).
2. Start at the beginning of the list.
3. For each car (node):
■ Remember the next car.
■ Make the current car point to the previous car (reversing the link).
■ Move to the next car, but remember the current one as the new "previous".
● Solution:

Python

class Node:
def __init__(self, data):
self.data = data
self.next = None

def reverse_linked_list(head):
"""
Reverses a singly linked list.

Args:
head: The head of the linked list.

Returns:
The head of the reversed linked list.
"""

previous = None
current = head
while current:
next_node = current.next # Remember the next car
current.next = previous # Reverse the link
previous = current # Move "previous" one step forward
current = next_node # Move "current" one step forward
return previous # The new head of the reversed list

Q4. Skyline Area


● Approach: Imagine you're looking at the skyline of a city from the side. Each building is a rectangle.
To find the total area, you need to find the area of each building that's "visible" and add them up.
● Logic:
1. For each building, find the tallest building to its left and the tallest building to its right.
2. The "visible" height of the current building is the difference between its height and the smaller of
the two tallest buildings on either side.
3. If the visible height is positive, calculate the area (visible height * width of the building, which
we'll assume is 1 for simplicity) and add it to the total area.
● Solution:

Python

def skyline_area(heights):
"""
Calculates the total area of a skyline.

Args:
heights: An array of integers representing the heights of buildings.

Returns:
The total area of the skyline.
"""

area = 0
for i in range(len(heights)):
left_max = 0
right_max = 0
for j in range(i - 1, -1, -1):
left_max = max(left_max, heights[j])
for j in range(i + 1, len(heights)):
right_max = max(right_max, heights[j])
current_area = min(left_max, right_max) - heights[i]
if current_area > 0:
area += current_area
return area
Q5. Shortest Path to Treasure

● Approach: Think of this like navigating a maze. You can move up, down, left, or right, and you want
to find the shortest route to the treasure.
● Logic:
1. You'll explore the map step-by-step, starting from your position.
2. Keep track of the places you've already visited so you don't go in circles.
3. Use a queue (like a line) to keep track of the places you need to explore next.
4. For each location, check if you can move up, down, left, or right. If you can, add those new
locations to the queue.
5. Keep track of how many steps you've taken to get to each location.
6. When you reach the treasure, the number of steps you took is the shortest path.
● Solution:

Python

from collections import deque

def shortest_path_to_treasure(grid):
"""
Finds the shortest path from the top-left corner to the bottom-right corner of a grid.

Args:
grid: A 2D grid of integers representing a map of a treasure island.

Returns:
The length of the shortest path to the treasure, or -1 if there is no path.
"""

if not grid or not grid[0]:


return -1

rows, cols = len(grid), len(grid[0])


queue = deque([(0, 0, 0)]) # (row, col, distance)
visited = set([(0, 0)])

while queue:
row, col, distance = queue.popleft()
if row == rows - 1 and col == cols - 1:
return distance

for dr, dc in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
new_row, new_col = row + dr, col + dc
if 0 <= new_row < rows and 0 <= new_col < cols and \
grid[new_row][new_col] == '1' and (new_row, new_col) not in visited:
visited.add((new_row, new_col))
queue.append((new_row, new_col, distance + 1))

return -1 # No path found

Aptitude Questions (without options- expect with options in test)- 1M*25M each

1. Question: If the cost of 5 apples is $10, what is the cost of 1 apple? Answer: $2
Explanation: $10 / 5 apples = $2/apple
2. Question: What is the next number in the sequence: 2, 4, 6, 8, ...? Answer: 10
Explanation: This is an arithmetic sequence with a common difference of 2.
3. Question: If a rectangle has a length of 10 cm and a width of 5 cm, what is its area? Answer: 50 sq
cm
Explanation: Area of a rectangle = length * width = 10 cm * 5 cm = 50 sq cm

Q4,5 are very similar to Q1,2,3

6. Question: A shopkeeper sells an item at a 20% profit. If he had bought it for 10% less and sold it for
Rs. 50 less, he would have still made a profit of 25%. What is the original cost price of the item?
Answer: Rs. 500
Explanation: Let the original cost price be Rs. x. Selling price = 1.2x New cost price = 0.9x New
selling price = 1.2x - 50 Profit = (1.2x - 50) - 0.9x = 0.3x - 50 Profit percentage = (0.3x - 50) / 0.9x *
100 = 25 Solving for x, we get x = 500

7. Question: A and B can complete a work in 12 days and 18 days respectively. They started the work
together but A left after 4 days. In how many days B will complete the remaining work? Answer: 10
days
Explanation: A's one day work = 1/12 B's one day work = 1/18 Together in one day = 1/12 + 1/18 =
5/36 Work done in 4 days = 5/36 * 4 = 5/9 Remaining work = 1 - 5/9 = 4/9 Time taken by B to
complete the remaining work = (4/9) / (1/18) = 8 days

8. Question: Two trains are running in opposite directions with speeds of 60 km/hr and 40 km/hr. If the
length of the first train is 120 meters and the length of the second train is 100 meters, how long will it
take for the two trains to cross each other? Answer: 6 seconds
Explanation: Relative speed = 60 + 40 = 100 km/hr = 100 * 5/18 m/s Total distance = 120 + 100 =
220 meters Time = Distance / Speed = 220 / (100 * 5/18) = 7.92 seconds

9. Question: A boat travels 24 km upstream in 4 hours and 36 km downstream in 3 hours. Find the
speed of the boat in still water and the speed of the stream.
Answer: Speed of boat = 7.5 km/h, Speed of stream = 1.5 km/h
Explanation: Let the speed of the boat in still water be x km/h and the speed of the stream be y
km/h. Upstream speed = x - y Downstream speed = x + y 24/(x - y) = 4 and 36/(x + y) = 3 Solving
these equations, we get x = 7.5 and y = 1.5

10. Question: In a mixture of 60 liters, the ratio of milk and water is 2:1. How much water must be
added to the mixture so that the ratio of milk and water becomes 1:2? Answer: 60 liters
Explanation: Milk = 60 * 2/3 = 40 liters, Water = 60 * 1/3 = 20 liters Let x liters of water be added.
40/(20 + x) = 1/2 Solving for x, we get x = 60

11. Question: What is the probability of getting a sum of 7 when two dice are rolled? Answer: 1/6
Explanation: There are 6 favorable outcomes: (1, 6), (2, 5), (3, 4), (4, 3), (5, 2), (6, 1) Total possible
outcomes = 6 * 6 = 36 Probability = 6/36 = ⅙

12. Question: If the simple interest on a certain sum of money for 3 years at 5% per annum is $150,
what is the principal amount? Answer: $1000
Explanation: Simple Interest = (P * R * T) / 100 150 = (P * 5 * 3) / 100 P = 1000

13. Question: A man can row 6 km/h in still water. If the speed of the current is 2 km/h, it takes 3 hours
more upstream than downstream for the same distance. Find the distance. Answer: 36 km
Explanation: Let the distance be x km. Upstream speed = 6 - 2 = 4 km/h Downstream speed = 6 + 2
= 8 km/h x/4 - x/8 = 3 Solving for x, we get x = 36

14. Question: The average of 5 consecutive odd numbers is 33. What is the largest of these numbers?
Answer: 37
Explanation: Let the numbers be x, x + 2, x + 4, x + 6, x + 8 (x + x + 2 + x + 4 + x + 6 + x + 8) / 5
= 33 5x + 20 = 165 x = 29 Largest number = x + 8 = 37

15. Question: If the radius of a circle is increased by 50%, what will be the percentage increase in its
area?
Answer: 125%
Explanation: Let the original radius be r. Original area = πr^2 New radius = 1.5r New area =
π(1.5r)^2 = 2.25πr^2 Increase in area = 2.25πr^2 - πr^2 = 1.25πr^2 Percentage increase = (1.25πr^2 /
πr^2) * 100 = 125%

16. Question: A man sells two articles for Rs. 4000 each, neither losing nor gaining in the deal. If he
sold one of them at a gain of 25%, the other article is sold at a loss of: Answer: 16.67%
Explanation: Let the cost price of the first article be x. Selling price = 1.25x = 4000 x = 3200 Cost
price of the second article = 8000 - 3200 = 4800 Loss = 4800 - 4000 = 800 Loss percentage = (800 /
4800) * 100 = 16.67%

17. Question: A and B can do a piece of work in 20 days and 30 days respectively. They work together
for 5 days and then A leaves. B finishes the remaining work alone. In how many days is the total
work finished? Answer:18 days
Explanation: A's one day work = 1/20 B's one day work = 1/30 Together in one day = 1/20 + 1/30 =
1/12 Work done in 5 days = 1/12 * 5 = 5/12 Remaining work = 1 - 5/12 = 7/12 Time taken by B to
complete the remaining work = (7/12) / (1/30) = 17.5 days Total time = 5 + 17.5 = 22.5 days
18. Question: A train 120 meters long passes a platform 180 meters long in 18 seconds. What is the
speed of the train in km/hr? Answer: 60 km/hr
Explanation: Total distance = 120 + 180 = 300 meters Speed = 300/18 m/s = 300/18 * 18/5 km/hr =
60 km/hr
19. Question: A man is 24 years older than his son. In two years, his age will be twice the age of his son.
Find the present age of his son. Answer: 22 years
Explanation: Let the son's present age be x years. Man's present age = x + 24 In two years, (x + 24)
+ 2 = 2(x + 2) x + 26 = 2x + 4 x = 22

20. Question: If the selling price is doubled, the profit triples. Find the profit percent. Answer: 100%
Explanation: Let the cost price be CP and the selling price be SP. Profit = SP - CP Given, 2SP - CP
= 3(SP - CP) 2SP - CP = 3SP - 3CP 2CP = SP Profit = SP - CP = 2CP - CP = CP Profit percentage =
(CP/CP) * 100 = 100%

21. Question: A sum of money amounts to Rs. 9800 after 5 years and Rs. 12005 after 8 years at the
same rate of simple interest. The rate of interest per annum is: Answer: 12%
Explanation: Simple Interest for 3 years = 12005 - 9800 = 2205 Simple Interest for 1 year = 2205/3
= 735 Principal = 9800 - (735 * 5) = 6125 Rate = (735 * 100) / (6125 * 1) = 12%

22. Question: A can do a piece of work in 10 days, B in 15 days. They work together for 5 days, the rest
of the work is finished by C in 2 days. If they get Rs. 3000 for the whole work, how should they
divide the money? Answer: A = Rs. 1500, B = Rs. 1000, C = Rs. 500
Explanation: A's one day work = 1/10 B's one day work = 1/15 Together in one day = 1/10 + 1/15 =
1/6 Work done in 5 days = 1/6 * 5 = 5/6 Remaining work = 1 - 5/6 = 1/6 C's one day work = (1/6) / 2
= 1/12 Ratio of their work = 1/10 : 1/15 : 1/12 = 6 : 4 : 5 A's share = 3000 * (6/15) = 1500 B's share
= 3000 * (4/15) = 1000 C's share = 3000 * (5/15) = 500

23. Question: Two pipes A and B can fill a tank in 20 and 30 minutes respectively. If both the pipes are
used together, then how long will it take to fill the tank? Answer: 12 minutes
Explanation: A's one minute work = 1/20 B's one minute work = 1/30 Together in one minute =
1/20 + 1/30 = 1/12 Time to fill the tank = 12 minutes

24. Question: A man buys a cycle for Rs. 1400 and sells it at a loss of 15%. What is the selling price of
the cycle? Answer: Rs. 1190
Explanation: Loss = 1400 * (15/100) = 210 Selling price = 1400 - 210 = 1190

25. Question: The average weight of 8 persons increases by 2.5 kg when a new person comes in place of
one of them weighing 65 kg. What might be the weight of the new person? Answer: 85 kg
Explanation: Total increase in weight = 8 * 2.5 = 20 kg Weight of the new person = 65 + 20 = 85 kg
Creative, Logical and Creative thinking questions- 25M

Question 1: The Lost City

You are an explorer who has stumbled upon an ancient, abandoned city in the heart of a dense jungle. The
city is eerily silent, with no signs of human life, but there are no signs of any struggle or disaster either.
Food is still on tables, tools are laid out as if work was suddenly stopped, and there are no bodies or
remains. What are some possible explanations for why the city was abandoned? Provide at least three
distinct hypotheses, and explain the reasoning behind each one.

Answers : The Lost City

● Sudden Environmental Disaster: Perhaps a rapid onset natural disaster occurred, like a volcanic
eruption with poisonous gas or a flash flood. The inhabitants may have been forced to flee quickly,
leaving everything behind. This explains the lack of bodies and the sense of immediate departure.
● Unexplained Mass Hysteria: A shared delusion or fear could have gripped the population, causing
them to abandon the city en masse. This might be triggered by a perceived supernatural threat or a
mass psychogenic illness. It explains the lack of logic in leaving a functioning city.
● Forced Relocation: An external force, like an invading army or a powerful governing body, could
have ordered the city's evacuation. This could have been for strategic reasons, resource control, or even
as a form of punishment. The lack of struggle suggests compliance.

Question 2: The Unexpected Guest

A close friend calls you at 3 AM to say they need your help. They arrive at your door with a suitcase,
asking you to store it for them and not to look inside. They seem distressed and refuse to explain what is
going on. How do you handle this situation? What questions do you ask, and what actions might you
take?

Sol : Handling the Situation:

● Prioritize Safety: Do not immediately agree to store the suitcase. Ask your friend to step inside while
maintaining a safe distance. Assess their demeanor and try to determine the urgency of the situation.
● Gather Information: Ask open-ended questions like, "What's going on?" or "How can I help?"
Express concern for your friend's well-being. Try to understand if they are in danger or if they have
done something that puts you at risk.
● Make a Decision:
○ If you feel unsafe, politely but firmly refuse to store the suitcase and encourage your friend to seek
help from authorities or a more appropriate resource.
○ If you trust your friend and believe they are in genuine need, you might agree to temporarily store
the suitcase, but make it clear you need some basic information about the contents to ensure your
own safety. Set a clear timeframe for them to retrieve it.
Question 3: Designing for the Future

Imagine you are tasked with designing a school for the year 2100. How would you approach this
challenge? What are some key considerations you would keep in mind, given the rapid advancements in
technology and the changing needs of society? Describe some innovative features you would include in
your school design.

● Technology Integration: Seamlessly integrate advanced technology into the learning environment.
This includes personalized learning platforms, AI tutors, virtual and augmented reality experiences,
and collaborative digital tools.
● Flexibility and Adaptability: Design modular spaces that can be easily reconfigured to accommodate
different learning styles, group sizes, and evolving pedagogical approaches.
● Sustainability and Well-being: Prioritize eco-friendly design features, natural light, green spaces, and
ergonomic furniture to promote physical and mental well-being.
● Focus on Skills: Emphasize the development of critical thinking, problem-solving, creativity, and
collaboration skills, which are essential for navigating an uncertain future.

Innovative Features:

● Personalized Learning Paths: AI-powered systems assess student strengths and weaknesses, tailoring
individual learning plans and providing customized support.
● Immersive Learning Labs: Dedicated spaces for hands-on experimentation with cutting-edge
technologies like 3D printing, robotics, and biotechnology.
● Global Collaboration Hubs: Virtual reality platforms enable students to connect and collaborate with
peers from around the world on real-world projects.
● Biophilic Design: Integrate natural elements like plants, water features, and natural light to create a
calming and stimulating learning environment.

You might also like