Loading Similar Posts
Question 1:
bool check(int num){
int count = 0;
while(num) {
if (num & 1) {
count++;
}
num = num>>1;
}
return (count==4);
}
int countans(vector<int> arr){
int n = arr.size();
int ans = 0;
for(int i=0; i<n; i++){
if(check(arr[i])){
ans++;
}
}
return ans;
}
Question: 2
vector<int> twoSum(vector<int>& nums, int target) {
unordered_map<int,int> mp;
for(int i = 0; i < nums.size(); i++){
if(mp.find(target - nums[i]) == mp.end()){
mp[nums[i]] = i;
}
else{
return{nums[i],target - nums[i]};
}
}
}