Amazon SDE Intern OA

I recently completed the Amazon Online Assessment and wanted to share my experience to help others prepare. The assessment consisted of two parts: a Data Structures & Algorithms coding problem and a Spring Boot backend debugging/fix task.

PART 1: DSA Problem - Delivery Logs and Warehouses (40 minutes)

Problem Statement:
You are given an array delivery_logs representing the number of logs in each delivery unit and an integer k representing the total number of warehouses. Each warehouse can only store logs from a single delivery unit (logs from different deliveries cannot mix). There are k/2 secure warehouses. Need to return the maximum number of secure logs possible.

Example 1:
Input: delivery_logs = [3,5,9,6], k = 4
Output: 9

Explanation:
Take 5 logs from 3rd delivery and put in warehouse 1. Take all 6 logs from 4th delivery and put in warehouse 2. Take remaining 4 logs from 3rd delivery and put in warehouse 3. Take all logs from 2nd delivery and put in warehouse 4. Warehouses become [5,6,4,5]. Secure warehouses (k/2 = 2) are the two largest: 5 and 4 which sum to 9.

Example 2:
Input: delivery_logs = [5,5,5,5,5,5], k = 4
Output: 10

Explanation:
Pick any 4 deliveries and place 5 logs each in 4 warehouses. Warehouses become [5,5,5,5]. Secure warehouses (k/2 = 2) can be any two warehouses, sum is 5+5=10.

PART 2: Spring Boot Backend - MovieDB (40 minutes)

This part involved fixing a MovieDB application with a broken watchlist feature. The code had a WatchlistController and a WatchlistRepository with all required methods already defined.

Bugs I Fixed:

Add to Watchlist - Missing Save Operation
Before: Controller was missing repository.save()
After: Added watchlistRepository.add(movie, user)

Remove from Watchlist - Missing Delete Operation
Before: Controller was missing repository.delete()
After: Added watchlistRepository.deleteByMovieAndUser(movie, user)

Add Operation - Duplicate Check
Added validation to prevent duplicate entries. If watchlistRepository.existsByMovieAndUser(movie, user) returns true, return HTTP 400 Bad Request with message "Movie already in watchlist"

Remove Operation - Existence Check
Added validation to ensure movie exists in watchlist. If !watchlistRepository.existsByMovieAndUser(movie, user), return HTTP 404 Not Found with message "Movie not found in watchlist"

Rate Limiting Implementation
The assessment required implementing rate limiting using a provided RateLimitingUtil class. The class already had a Map<String, List> to store user operations. I implemented registerOperation to append the current timestamp to the user's list. I implemented isRateLimited to count operations in the last 2 minutes and return true if the count exceeds the limit. I then applied rate limiting to both add to watchlist and remove from watchlist endpoints by checking isRateLimited and returning HTTP 429 Too Many Requests if rate limited, otherwise calling registerOperation.

Comments (5)