UBER OA QUESTION HELP NEEDED
Anonymous User
1814

A building is to be created with a given number of floors.There can be three different types of floors in the building.
The owner of the building has two wishes about the design of the building:
1)Ther can not be more than two consecutive office floors in the entire the building.
2)Ther can not be more than one cafteria in the entire building.
Given number of floors,return the total possible number of ways to create this building according to owners wishes.
return the answer module 10^9+7.
Input-2
output-8
RR,RO,RC,OR,OO,OC,CR,CO (O-OFFICE,R-RESIDENTIAL,C-CAFTERIA)
I was able to come up with a recursive solution but was not able to memoize it.Please can anyone help me.
'''
int findtotal(int n,int cnt,bool flag){
if(n==0){
return 1;
}
int ans=0;
if(cnt<2)ans+=findtotal(n-1,cnt+1,flag);
ans+=findtotal(n-1,0,flag);
if(flag==false)ans+=findtotal(n-1,0,true);
return ans;
}
int main()
{
int n;cin>>n;
bool flag=false;
int z=findtotal(n,0,flag);
cout<<z<<"\n";
}
'''

Comments (11)