21BCS22 - Mohsin-DAY 2
21BCS22 - Mohsin-DAY 2
DAY : 02
Program Code:
#include <bits/stdc++.h> using
namespace std;
int main() {
int t; cin>>t;
while(t--){ int n;
cin>>n; int a[n];
for(int i=1;i<=n;i++){
cin>>a[i];
}
vector <int> count(n+1,0); for(int
i=1;i<=n;i++){
count[a[i]]++;
}
sort(count.begin(),count.end());
if(count[n]!=count[n-1])
cout<<"yes"<<endl; else
cout<<"no"<<endl;
}
return 0;
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Output:
Program Code:
#include <bits/stdc++.h> using
namespace std;
int main() {
// your code goes here
int t,n;cin>>t;
while(t--)
{ cin>>n;
int a,x=0;
while(n--){
cin>>a;
x^=a;
}
cout<<x<<endl;
}
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Output:
Output:
c=a[i]; } }
cout<<c<<endl; }
return 0;
}
Program Code:
class Solution { public: vector<int>
searchRange(vector<int>& nums, int target) {
int left = binarySearch(nums, target, true);
int right = binarySearch(nums, target, false);
Output:
private: int binarySearch(vector<int>& nums, int target, bool
findLeft) { int low = 0;
int high = nums.size() - 1;
int index = -1; while (low
<= high) {
int mid = low + (high - low) / 2;
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
if (nums[mid] == target) {
index = mid;
if (findLeft)
{ high = mid -
1;
} else {
low = mid + 1;
}
} else if (nums[mid] < target) {
low = mid + 1;
} else {
high = mid - 1;
}
}
return index;
}
};
Output:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Output:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING