QUESTION 1 Correct Answer:+5 Marks Given the sorted array arr = [5, 10, 15, 20, 25, 30,…
- User
QUESTION 1
Correct Answer:+5 Marks
Given the sorted array arr = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50], which of the following rearrangements ensures that :
arr[o] >= arr[1] <= arr[2] >= arr[3] <= arr[4] and so on?
[5, 10, 15, 20, 25, 30, 35, 40, 45, 50]
[5, 15, 10, 20, 25, 35, 30, 40, 45, 50]
[10, 5, 20, 15, 30, 25, 40, 35, 50, 45]
[10, 5, 20, 15, 25, 30, 40, 35, 45, 50]
- Assistant
To solve this problem, we need to rearrange the elements of the array so that it satisfies the condition
arr[0] >= arr[1] <= arr[2] >= arr[3] <= arr[4]and so on. This means that the array should take a zig-zag pattern starting with the peak (a larger value).Let's analyze the given options:
-
[5, 10, 15, 20, 25, 30, 35, 40, 45, 50]
- This follows an increasing order and does not satisfy the zig-zag condition.
-
[5, 15, 10, 20, 25, 35, 30, 40, 45, 50]
-
- User
always give ans only
- Assistant
[10, 5, 20, 15, 30, 25, 40, 35, 50, 45]
- User
QUESTION 3
Correct Answer:+5 Marks
FUNCTION fun(a, b) RETURN (a + b - 2 * (a AND b))
What does the above fun function return?
It finds the sum of two numbers a and b.
It swaps the values of a and b.
It finds the AND of two numbers a and b.
It finds the XOR of two numbers a and b.
- Assistant
It finds the XOR of two numbers a and b.
- User
QUESTION 4
Correct Answer:+5 Marks
Given the strings X="geeks" and Y="grand" with k=2, what is the minimum cost to convert X such that the Longest Common Subsequence (LCS) of X and Y after conversion is of length k? Note: The cost of conversion is calculated as the XOR of the old character value and the new character value, where the character value of 'a' is 0, 'b' is 1, and so on.
3
11
4
1
- Assistant
1