QUIZ:
1) 12
2) [9, 7, 6, 5, 4, 3, 2, 1] , [5, 2, 1, 7, 3, 4, 8, 6]
3) Yes
4) 7
5) List L sorted in descending order
6) O(n2)
7) O(logN)
8) I.O(logn), II.O(1)
9) O(nloglogn)
10) (a) If p < x > q , then x is the maximum in the array,
(c) If p < x < q , then the maximum element is in the right half of the array.
PQ1:
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
long long x;
cin >> n >> x;
vector<long long> arr(n);
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int idx = -1;
for (int i = 0; i < n; i++) {
if (arr[i] == x) {
idx = i;
break;
}
}
cout << idx << endl;
}
return 0;
}
PQ2:
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
vector<long long> arr(n);
for (int x = 0; x < n; x++) {
cin >> arr[x];
}
sort(arr.rbegin(), arr.rend());
int critical_x = -1;
for (int x = 1; x <= n; x++) {
if (arr[x - 1] >= x && (x == n || arr[x] < x)) {
critical_x = x;
break;
}
}
cout << critical_x ;
if(t!=0)cout<<endl;
}
return 0;
}