Amazon Interview Question for Applications Developers


Country: India
Interview Type: In-Person




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

Using C++ since that;s my favorite language but hope you get the idea.

There are various things you need to look into here....
First of all the requirements of Reviewing a product i.e, various things customers should be able to do:
Let;s assume that he could do following things
a) Rate with star rating for the product.
b) Add a Review which is just a char array of limited size.
c) edit a review.

Now each product will have a Review object attached to it.
let's say for simplicity that review object looks like

class ReviewData{
  private:
    int starRating;
    std::string review;

   // have setters and getters in here
}

class Product{
 //other details
 ReviewData* myReviewDetails;

 //mutex for writing the review since you can try different application for editing
 //function to update the database which usually is web-service call 
}

- AJ Gauravdeep September 07, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public enum ProductCategory
{
Home, Daily, Food
}

public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public ProductCategory ProductCategory { get; set; }
}

public class Review
{
public int Id { get; set; }
public int ProductId { get; set; }
public string Comment { get; set; }
public int UserId { get; set; }
public DateTime ReviewAt { get; set; }
public int Rating { get; set; }
}

public class User
{
public int Id { get; set; }
public string Name { get; set; }
}

public interface IReviewActivity
{
void PostReview(Review Rev);
void DeleteReview(Review Rev, User User);
}

public class ReviewActivity
{
List<Review> _review = new List<Review>();
public ReviewActivity()
{
}
public void PostReview(Review Rev)
{
_review.Add(Rev);
}
public void DeleteReview(Review Rev, User User)
{
if (_review.Where(f => f.UserId == User.Id).Count() > 0)
{
_review.Remove(Rev);
}
else
throw new Exception("Invalid Action");
}
public List<Review> GetReviewByProductId(int Id)
{
return _review.Where(f => f.ProductId == Id).OrderBy(f=>f.ReviewAt).Take(10).ToList();
}
public int GetAverageRatingByProductId(int Id)
{
int Count = _review.Where(f => f.ProductId == Id).Count();

if (Count != 0)
return _review.Where(f => f.ProductId == Id).Sum(f => f.Rating) / Count;
else
return 0;
}

}

- Anonymous November 19, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public enum ProductCategory
    {
        Home, Daily, Food
    }

    public class Product
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public ProductCategory ProductCategory { get; set; }
    }

    public class Review
    {
        public int Id { get; set; }
        public int ProductId { get; set; }
        public string Comment { get; set; }
        public int UserId { get; set; }
        public DateTime ReviewAt { get; set; }
        public int Rating { get; set; }
    }
    
    public class User
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }

    public interface IReviewActivity
    {
        void PostReview(Review Rev);
        void DeleteReview(Review Rev, User User);
    }

    public class ReviewActivity
    {
        List<Review> _review = new List<Review>();
        public ReviewActivity()
        {
        }
        public void PostReview(Review Rev)
        {
            _review.Add(Rev);
        }
        public void DeleteReview(Review Rev, User User)
        {
            if (_review.Where(f => f.UserId == User.Id).Count() > 0)
            {
                _review.Remove(Rev);
            }
            else
                throw new Exception("Invalid Action");
        }
        public List<Review> GetReviewByProductId(int Id)
        {
            return _review.Where(f => f.ProductId == Id).OrderBy(f=>f.ReviewAt).Take(10).ToList();
        }
        public int GetAverageRatingByProductId(int Id)
        {
            int Count = _review.Where(f => f.ProductId == Id).Count();

            if (Count != 0)
                return _review.Where(f => f.ProductId == Id).Sum(f => f.Rating) / Count;
            else
                return 0;  
        }

    }

- Anonymous November 19, 2017 | Flag Reply


Add a Comment
Name:

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

Books

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

Videos

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