Amazon Interview Question for Software Engineer / Developers

Comment hidden because of low score. Click to expand.
of 0 vote

Each message will be stored in some persistance unit with schema like
Message: postedByUserId, MessageId, MessageText, MessagePostTime
User: userId, userName, Receiver(will be having some serialized listening userIds, can be persisted as separate relation), serialized message Ids.

1) PostMessage(Reciever,Messsage): The user will be holding the reference for receiver. The receiver class will be holding the list of subscriber userIds (and might be some other action specific parameters)
Receiver will append the new message id at the end of persisted subscribed_messages column. That can be the way through which messages are published

2) getallmessageofuser(user) will query for the postedbyuserid.

- Hinax December 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
of 1 vote

Class structure would look something like this:

User {
	String name;
	//other properties
	list<Post> posts;
	list<User> subscribers;

	public void getAllMessageOfUser(User user) {
		if(subscribers == null)
			subscribers = new List<User>();

	public List<User> getSubscriptionList(){
		return subscribers;
Post {
	String text;
	User owner;
	String comment;
	public void postMessage(String text, User user) {
		this.owner = user;
		this.text = text;
		for(User u : user.getSubscriptionList()) {
			u.notify(user, text);

Here we can use Observer pattern.

- inheritance February 18, 2013 | Flag Reply

Add a Comment

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.


is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More


CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More