Aptitude and Tech interview questions (Sunday 07)

Q1. What is the next number in the sequence 2, 5, 10, 17, 26, __?
Q2. If the price of a shirt is reduced by 20%, and then reduced by an additional 10%, what is the final price as a percentage of the original price?
Q3. If 3 people can paint a house in 4 days, how many people are needed to paint the same house in 2 days?
Q4. Write a Python program that uses the reduce function to find the product of a list of integers entered by the user.
Q5. Suppose you have a database table named orders that contains information about customer orders, including the customer name, product name, and order date. Write a MySQL query to create a view named monthly_orders that displays the total number of orders for each month and year.
The orders table has the following columns:
order_id (int)
customer_name (varchar)
product_name (varchar)
order_date (date)
Your view should have the following columns:
year (int)
month (int)
total_orders (int)
Your query should group the orders by month and year, and calculate the total number of orders for each group. The year and month columns should be extracted from the order_date column.
Here’s an example output of the monthly_orders view:

year month total_orders
2022 1 10
2022 2 12
2022 3 15
2022 4 8
2022 5 9


Q1. The sequence follows the pattern of adding successive odd numbers starting from 1, so the next number is 37.
Q2. The first reduction is 20%, which means the shirt will cost 80% of the original price. The second reduction is 10%, which means the shirt will cost 90% of the 80% of the original price. So the final price is 72% of the original price.
Q3. This problem involves an inverse proportionality between the number of people and the time taken to paint the house. If the number of people doubles, the time taken will halve. So if the time taken is halved from 4 days to 2 days, the number of people needed will double from 3 to 6.
from functools import reduce

Get a list of integers from the user

lst = list(map(int, input("Enter a list of integers: ").split()))

Use reduce function to find the product of the list

product = reduce(lambda x, y: x * y, lst)

Print the product of the list

print(“Product of the list:”, product)

Q5. CREATE VIEW monthly_orders AS
SELECT YEAR(order_date) AS year,
MONTH(order_date) AS month,
COUNT(*) AS total_orders
FROM orders
GROUP BY YEAR(order_date), MONTH(order_date);