Zypp Electric - 12207745
Zypp Electric - 12207745
Answer: b) Void
Answer: c) throw
Answer: b) Break halts the execution and forces the control out of the loop
Code:
import java.util.*;
set.addAll(list);
list.clear();
list.addAll(set);
return list;
}
ArrayList<Integer>
list = new ArrayList<>(
Arrays
.asList(1,2,4,2,4,5));
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:
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;
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;
}
Zypp Electric
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
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?
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: c) To perform conditional logic and return different values based on specified conditions.
a) ALTER INDEX
b) MODIFY INDEX
c) ADD INDEX
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
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:
Now, imagine you frequently execute the following query to retrieve employees earning a salary
greater than a specified amount within a particular department:
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:
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.
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.
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
Ques 2
Solution:
Thank You…..!