0% found this document useful (0 votes)
49 views11 pages

Zypp Electric - 12207745

The document contains a software engineer test with 10 multiple choice questions testing Java fundamentals and OOP concepts. It also contains a SQL test with 10 questions covering topics such as joins, indexes, and window functions. Finally, it discusses a scenario for optimizing query performance on a database table through appropriate indexing.

Uploaded by

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

Zypp Electric - 12207745

The document contains a software engineer test with 10 multiple choice questions testing Java fundamentals and OOP concepts. It also contains a SQL test with 10 questions covering topics such as joins, indexes, and window functions. Finally, it discusses a scenario for optimizing query performance on a database table through appropriate indexing.

Uploaded by

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

Zypp Electric

Software Engineer Test 1 - Time:- 45 Mins

Name: Laksh Patra Reg No- 12207745 Date: 14-02-2024

Follow any specific instructions provided with each question.

1. Which of the following is a superclass of every class in Java?


a) ArrayList
b) Abstract class
c) Object class
d) String

Answer: c) Object class

2. Which one of the following is not an access modifier?


a) Protected
b) Void
c) Public
d) Private

Answer: b) Void

3. Which of these is the correct way of inheriting class A by class B?


a) class B + class A {}
b) class B inherits class A {}
c) class B extends A {}
d) class B extends class A {}

Answer: c) class B extends A {}

4. Which of these keywords are used for generating an exception manually?


a) try
b) catch
c) throw
d) check

Answer: c) throw

5. What happens if we put a key object in a HashMap which exists?


a) The new object replaces the older object
b) The new object is discarded
c) The old object is removed from the map
d) It throws an exception as the key already exists in the map
Answer: a) The new object replaces the older object
6. What is the process of defining a method in a subclass having same name & type signature as a
method in its superclass?
a) Method overloading
b) Method overriding
c) Method hiding
d) None of the mentioned

Answer: b) Method overriding

7. What is the use of final keyword in Java?


a) When a class is made final, a subclass of it can not be created
b) When a method is final, it can not be overridden.
c) When a variable is final, it can be assigned value only once.
d) All of the above

Answer: d) All of the above

8. What is true about a break?


a) Break stops the execution of entire program
b) Break halts the execution and forces the control out of the loop
c) Break forces the control out of the loop and starts the execution of next iteration
d) Break halts the execution of the loop for certain time frame

Answer: b) Break halts the execution and forces the control out of the loop

9. How To Remove Duplicate Elements From ArrayList In Java? Input :


[1,2,4,2,4,5]
Output : [1,2,4,5]

Code:

import java.util.*;

public class Arpan {

public static <T> ArrayList<T> removeDuplicates(ArrayList<T> list)


{
Set<T> set = new LinkedHashSet<>();

set.addAll(list);
list.clear();

list.addAll(set);
return list;
}

public static void main(String args[])


{

ArrayList<Integer>
list = new ArrayList<>(
Arrays
.asList(1,2,4,2,4,5));

System.out.println("ArrayList Element: "


+ list);
System.out.println("\n");

ArrayList<Integer>
newList = removeDuplicates(list);
System.out.println("Remove Duplicate Values:"
+ newList);
}
}

10. Given a sorted array of distinct integers and a target value, return the index if the target is found.
If not, return the index where it would be if it were inserted in order. You must write an algorithm
with O(log n) runtime complexity. Input: nums =
[1,3,5,6], target = 5 Output: 2

Solution:

Binary Search Approach

Binary search is a searching algorithm used in a sorted array.

It operates by repeatedly dividing the search interval in half.

The key idea behind binary search is to exploit the fact that the array is sorted which allows us to reduce the
time complexity to O(log N).

Code:

#include<iostream>
using namespace std;

int f_index(int arr[], int n, int K)


{
int start = 0;
int end = n - 1;
while (start <= end) {
int mid = (start + end) / 2;

if (arr[mid] == K)
return mid+1;
else if (arr[mid] < K)
start = mid + 1;
else
end = mid - 1;
}
return end + 2;
}

int main()
{
int arr[] = { 1, 3, 5, 6 };
int n = sizeof(arr) / sizeof(arr[0]);
int K = 3;
cout << f_index(arr, n, K) << endl;
return 0;
}

Time complexity: O(log n).

Zypp Electric

Software Engineer Test 2 - Time:- 45 Mins

Name : Arpan Sharma Reg No- 12207721 Date: 14-02-2024

SQL Questions:

1. Which MySQL function would you use to concatenate strings from multiple rows into a single string?

a. CONCAT_WS
b. GROUP_CONCAT
c. CONCAT
d. STRING_CONCAT

Answer: b) GROUP_CONCAT

2. Which SQL keyword is used to define a window function?

a. WINDOW
b. OVER
c. PARTITION
d. WITH

Answer: b) OVER

3. In a SQL query containing multiple clauses (e.g., SELECT, FROM, WHERE, JOIN, GROUP BY,
ORDER BY, what is the typical execution order?

a) FROM/JOIN, WHERE, GROUP BY, HAVING, SELECT , ORDER BY, LIMIT/OFFSET


b) SELECT, FROM/JOIN, WHERE, GROUP BY, HAVING ORDER BY, LIMIT/OFFSET
c) SELECT, FROM/JOIN, WHERE, ORDER BY, GROUP BY, HAVING, LIMIT/OFFSET
d) WHERE, FROM, GROUP BY, HAVING, ORDER BY, SELECT, LIMIT/OFFSET

Answer: a) FROM/JOIN, WHERE, GROUP BY, HAVING, SELECT , ORDER BY, LIMIT/OFFSET

4. In MySQL, which of the following commands can be used to remove an index from a table?

a) DROP INDEX
b) DELETE INDEX
c) REMOVE INDEX
d) ERASE INDEX

Answer: a) DROP INDEX

5. What is the primary purpose of the CASE WHEN statement in SQL?

a) To define conditions for filtering rows in a WHERE clause.


b) To specify the order in which columns should be sorted in a result set.
c) To perform conditional logic and return different values based on specified conditions.
d) To join multiple tables based on common columns.

Answer: c) To perform conditional logic and return different values based on specified conditions.

6. In MySQL, which statement is used to add an index to an existing table?

a) ALTER INDEX
b) MODIFY INDEX
c) ADD INDEX
d) CREATE INDEX

Answer: d) CREATE INDEX

7. Which JOIN type in MySQL is suitable for combining rows from two tables even if there is no match
found in the other table?
a) INNER JOIN
b) LEFT JOIN
c) RIGHT JOIN
d) FULL OUTER JOIN

Answer : b) LEFT JOIN

8. In SQL, what is the typical syntax for using the LAG function?

a) LAG(column_name)
b) LAG(column_name, n)
c) LAG(n, column_name)
d) LAG

Answer: b) LAG(column_name, n)

9. Consider the following scenario where you have a table named "employees" in a MySQL database.
The table has the following structure:

CREATE TABLE employees (


emp_id INT PRIMARY KEY,
emp_name VARCHAR(50),
department_id INT,
salary DECIMAL(10, 2),
hire_date DATE );

Now, imagine you frequently execute the following query to retrieve employees earning a salary
greater than a specified amount within a particular department:

SELECT emp_name, salary


FROM employees
WHERE department_id = ? AND salary > ?
ORDER BY hire_date DESC;

Based on the provided query, which column or columns would you recommend indexing on the
"employees" table to optimize the query's performance? Write the index structure and explain your
reasoning.

Solution:
Ques 1
Recommended Indexes for Optimized Performance:
Based on the provided query, I propose creating two distinct indexes on the "employees" table to
enhance its performance:

1. Combined Covering Index:

 Structure: (department_id, salary)


 Type: Covering index

Reasoning:

 This design takes advantage of the "leading column optimization" principle. Since the query
filters by department_id first, followed by salary, combining them in a single index allows
the database to efficiently locate relevant rows directly from the index, minimizing table
access.
 Moreover, covering indexes encompass all columns referenced in the SELECT clause
(emp_name and salary in this case). This eliminates the need to fetch data from the table
itself, further boosting performance.

2. Separate Index for Sorting:

 Structure: hire_date
 Type: Non-covering index

Reasoning:

 While hire_date isn't explicitly involved in filtering, the ORDER BY DESC clause utilizes it
for descending order sorting. Having an index on this column significantly improves the
sorting efficiency.
 This index operates independently, aiding in efficiently ordering the already filtered data
obtained from the combined covering index.

Benefits of this Approach:


 This strategy strikes a balance between efficient filtering (utilizing the combined index) and
optimized sorting (leveraging the separate index).
 Covering indexes can dramatically improve performance, especially for selective queries that
retrieve a small fraction of the data.
 Separate indexes on frequently used sorting columns enhance efficiency even if they're not
directly incorporated into the WHERE clause.

Additional Considerations:
 Index selection should factor in the size and cardinality of each column. Covering indexes
tend to be larger, so carefully evaluate the performance gains in relation to their size.
 If the query pattern undergoes frequent changes, materialized views might be a more suitable
alternative to indexing.

10. The ideal time between when a customer places an order and when the order is delivered is below or
equal to 45 minutes. You have been tasked with evaluating delivery driver performance by calculating
the average order value for each delivery driver who has delivered at least once within this 45-minute
period. Your output should contain the driver ID along with their corresponding average order value.

Table: Delivery_details

Create Table Query

CREATE TABLE orders (


customer_placed_order_datetime DATETIME,
placed_order_with_restaurant_datetime DATETIME,
driver_at_restaurant_datetime DATETIME,
delivered_to_consumer_datetime DATETIME,
driver_id INT,
restaurant_id INT,
consumer_id INT,
is_new BOOLEAN,
delivery_region VARCHAR(255),
is_asap BOOLEAN,
order_total FLOAT,
discount_amount FLOAT,
tip_amount FLOAT,
refunded_amount FLOAT );

Ques 2
Solution:
Thank You…..!

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