I understand that checkmodulo() is being used to count the number of factors of each element , and then we are returning the max number of factors any element in the array , but I dont see how this works ? Can someone explain
Q1. Solution.
#include <bits/stdc++.h>
using namespace std;
void checkmodulo(int x,map<int,int> &mpp){
int i=2;
while(i<=x){
if(x%i==0){
mpp[i]++;
}
i++;
}
}
int main()
{
int arr[]={3,6,9,12,15};
int n=5;
map<int,int>mpp;
for(int i=0;i<n;i++){
checkmodulo(arr[i],mpp);
}
int maxi =0;
for(auto it:mpp){
if(it.second>maxi){
maxi = it.second;
}
}
cout<< n-maxi;
}
- To solve this problem, We can perform string matching using a pointer.
Steps:
Python Code:
def missingWords(s, t):
s_words = s.split()
t_words = t.split()
missing = []
t_index = 0
for word in s_words:
if t_index < len(t_words) and word == t_words[t_index]:
t_index += 1
else:
missing.append(word)
return missing
In which college these questions were asked?