Amazon Interview Question
SDE-2sCountry: United States
Interview Type: In-Person
I have writtern considering only one type (Type A) of newspaper and it can exteded for other types as well. I have used builder design pattern for implementation.
My approach is like:
class newspaper
{
public:
string *s;
virtual void political_news(string *s);
virtual void sports_news(string *s);
virtual void entertainment_news(string *s);
};
class News_Articles: public newspaper
{
public:
void political_news(string *s)
return s;
void entertainment_news(string *s)
return s;
void sports_news(string *s)
return s;
};
class newspaper_type
{
public:
virtual void create_politicalnews();
virtual void create_entertainmentnews();
virtual void create_sportsnews();
};
class TypeA : public newspaper_type
{
public:
void create_politicalnews()
{
cout<<this.political_news("type A");
}
void create_sportsnews()
{
cout<<this.sports_news("type A");
}
void create_entertainmentnews()
{
cout<<this.entertainment_news("type A");
}
}
class monitor
{
private:
newspaper_type *temp;
public:
monitor(newspaper_type *a)
{
temp=a;
}
void return_news()
{
temp->create_politicalnews();
temp->create_sportsnews();
temp->create_entertainmentnews();
}
}
class subscription {
string name;
string URI;
string channel_type;
TimeRange range;
FeedInterval interval;
boolean is_push;
list<Contents> contents;
int max_contents_entries;
int max_contents_size;
Interval last_read;
void get_new_contents();
// get new contents and update the contents
};
class Monitor {
list<subscription> s;
int min_read_interval;
void gather_reads(); // go over the subs and call the get_new_contens
// if the last_interval + interval < time now.
// if is_push, then ignore.
// if range condition met, then call the remove subscriton on the news
int min_read_interval;
void runner(); // runs after the min_read_interval and call
// gather reads
};
class app {
list<subscription> sub;
Monitor m;
public:
boolean get_subscription(string url);
// and update the monitor with the subscrition
string list_subscritions();
void remove_subsciption(string uri); // lok for uri in the subscritopn list
void display_reads();
};
- satis June 10, 2017