2)https://leetcode.com/discuss/interview-question/1934253/google-online-assessment-hybrid-se
quence (it contains the question (hybrid maximum)
(solution below)
3 ,4)
https://leetcode.com/discuss/interview-question/3760132/Google-SWE-Intern-OA-2023-(India)-
Both-Questions (it contains two questions)
3) code: (special subsequence)
#include<bits/stdc++.h>
using namespace std;
#define int long long
int MOD=1e9+7;
const int N = 100005;
int f[N],invf[N];
void precomputeFactorials()
{
f[0]=1;
for(int i=1;i<N;i++)
f[i]=(f[i-1]*i)%MOD;
for(int i=0;i<N;i++)
invf[i]=inverse(f[i]);
}
while(t--)
{ int k;
cin>>k;
string s;
cin>>s;int n=s.size();
cout<< solve(n,k,s);
}
}
4) code : Find Arrays
#include<bits/stdc++.h>
using namespace std;
#define int long long
int mod = 1e9 +7;
const int LIMIT = 1001;
int digit[LIMIT];
int dp[101][LIMIT];
int get_sum(int n){
int sum=0;
while(n!=0){
sum+=(n%10);
n/=10;
}
return sum;
}
void pre_compute(){
for(int i=0;i<LIMIT;i++){
digit[i]=get_sum(i);
}
}
int no_of_ways(vector<int> &s,int n){
int ans=0;
dp[0][0]=1;
vector<int> pref(LIMIT,1);
for(int i=1;i<=n;i++){
for(int j=0;j<LIMIT;j++){
if(s[i-1]==digit[j]){
dp[i][j] = pref[j-1];
}
else {
dp[i][j]=0;
}
}
pref[0]=0;
for(int j=1;j<LIMIT;j++){
pref[j]=pref[j-1]+dp[i][j];
}
}
for(int i=0;i<LIMIT;i++){
ans+=dp[n][i];
ans%=mod;
}
return ans;
}
int32_t main(){
pre_compute();
int t;
cin>>t;
while(t--){
int n;
cin>>n;
vector<int> s(n);
for(int i=0;i<n;i++){
cin>>s[i];
}
cout<<no_of_ways(s,n)<<"\n";
}
}
5)https://leetcode.com/discuss/interview-question/1366276/google-oa-prime-path
That contains code may work. (keepMotivated 494 July 27, 2021 11:46 PM (this one))
sieve();
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
vector<vector<int>>G(n,vector<int>(n,0));
for(int i = 0;i<n;i++)
{
for(int j = 0;j<n;j++)
{
cin>>G[i][j];
}
}
vector<vector<int>>distinctprime(n,vector<int>(n));
for(int i = 0;i<n;i++)
{
for(int j = 0;j<n;j++)
{
distinctprime[i][j] = query(G[i][j]);
}
}
priority_queue<pair<ll,pair<ll,ll>>,vector<pair<ll,pair<ll,ll>>>,greater<pair<ll,pair<ll,ll>>> > pq;
vector<vector<ll>>dist(n,vector<ll>(n,LONG_MAX));
dist[0][0] = 0LL;
pq.push({0LL,{0,0}});
// cout<<dist[n-1][n-1];
while(!pq.empty())
{
auto it = pq.top();
pq.pop();
int x = it.second.first;
int y = it.second.second;
ll val = distinctprime[x][y];
for(int k = -val+x;k<=x+val;k++)
{
for(int j = -val+y;j<=y+val;j++)
{
if(k<0 || j<0 || k>=n || j>=n) continue;
if(k == x && j==y) continue;
if( abs(x-k) + abs(y-j) <= val)
{
if(dist[k][j] > dist[x][y] + sqrt(G[x][y])*1LL)
{
dist[k][j] = dist[x][y] + sqrt(G[x][y])*1LL;
pq.push({dist[k][j],{k,j}});
}
}
}
}
}
cout<<dist[n-1][n-1]<<"\n";
}
return 0;
}