Two Amazon Intern OA questions — full AC. Q1 is a greedy grouping problem, Q2 is a divisor-based greedy. Pure logic breakdown below, no code.

Exam Overview
| Item | Details |
|---|---|
| Platform | HackerRank |
| Questions | 2 |
| Difficulty | Medium |
| Role | Intern SDE |
| Result | Full AC |
Q1: Security Level Grouping

Problem Core
Given a list of people, each with a security level. Assign them to groups such that:
- Each group contains only one security level
- Any two groups differ in size by at most 1
Find the minimum number of groups needed.
Approach
Step 1: Count frequencies
Use a hash map to count how many people have each security level.
Step 2: Think about the global constraint
The constraint "any two groups differ by at most 1" means all groups globally can only have sizes k or k+1 for some integer k. This is the key equivalence.
Step 3: Enumerate group size k
- For each security level with frequency
cnt, splitting into groups of sizekrequiresceil(cnt / k)groups - Total groups = sum of
ceil(cnt / k)across all levels - Enumerate
kfrom 1 tomax_cntand take the minimum total
Complexity
- Time: O(n + L · max_cnt) — L is number of distinct levels, max_cnt is the max frequency
- Space: O(L)
Key Insight
The "differ by at most 1" constraint translates directly to: all group sizes globally must be either k or k+1. Enumerate k, apply ceiling division per level, sum up.
Q2: Divisor Replacement for Minimum Sum
Problem Core
Given an integer array, each element can be replaced by any of its divisors that exists in the array (including itself). Minimize the total sum after replacements.
Approach
Greedy direction: to minimize sum, replace each number with the smallest possible divisor available in the array.
Steps:
- Sort and deduplicate the array into an ordered set
S - For each element
xinS, find its smallest divisor present inS:- Iterate through elements of
Ssmaller thanx; ifx % d == 0, thendis the answer forx - Map
xtod; if no suchdexists,xmaps to itself
- Iterate through elements of
- Apply the mapping to the original array and sum up
Optimization: processing in sorted order means once you find the smallest divisor for x, you can reuse it — if d already maps to something smaller, chain the replacement.
Complexity
- Time: O(n log n + m²) — n is array length, m is number of distinct elements
- Space: O(m)
Key Insight
The problem reduces to: build a replacement map where each number maps to its smallest divisor within the array. Sorting first ensures greedy correctness — smaller elements are processed before larger ones that might depend on them.
Side-by-Side Comparison
| Problem | Core Technique | Time | Space |
|---|---|---|---|
| Q1 Security Grouping | Frequency count + enumerate group size k | O(n + L·max_cnt) | O(L) |
| Q2 Divisor Replacement | Sort + greedy smallest divisor in array | O(n log n + m²) | O(m) |
Common Pitfalls
| Problem | Pitfall | Correct Direction |
|---|---|---|
| Q1 | Sorting all people and grouping ignoring levels | Bucket by level first, then enumerate global k |
| Q1 | Minimizing groups per level independently | Global constraint: all groups must be size k or k+1 |
| Q2 | Full prime factorization for each element | Only need smallest divisor present in the array |
| Q2 | Forgetting the divisor must exist in the array | Build the set first, only map to elements within it |
Amazon Intern OA Strategy
What to Expect
- Platform: HackerRank
- Problem style: greedy, math, sorting — logical reasoning matters more than code volume
- Core test: can you quickly restate the problem in a simpler equivalent form?
- Data scale is moderate — O(n²) often passes, but O(n log n) is safer
On-the-Day Tips
- Q1-style grouping: translate fuzzy constraints ("differ by ≤ 1") into concrete math ("all sizes are k or k+1"), then enumerate
- Q2-style replacement: greedy direction is clear — minimize means find the smallest valid replacement
- Sorting is often the key first step — many greedy properties hold naturally on sorted data
- Watch for hidden constraints like "divisor must exist in the array" — easy to miss under pressure
- Run the provided samples before submitting
Related LeetCode Practice
| # | Problem | Connection |
|---|---|---|
| 2966 | Divide Array Into Arrays With Max Difference | Q1: group size constraints |
| 945 | Minimum Increment to Make Array Unique | Q1: greedy allocation |
| 2344 | Minimum Deletions to Make Array Divisible | Q2: divisor relationships |
| 1998 | GCD Sort of an Array | Q2: factor-array relationships |
🚀 Need Amazon Intern OA Assistance?
oavoservice specializes in full-service OA/VO support for top North American tech companies. Amazon Intern OA is one of our core service areas with extremely high HackerRank question pool coverage.
Add WeChat now: Coding0201
You'll get:
- ✅ Amazon OA real-time assistance (screen share + live typing hints)
- ✅ HackerRank real question bank (80%+ high-frequency coverage)
- ✅ 1-on-1 mock OA + detailed feedback
- ✅ VO interview assistance (algorithms + system design)
📱 WeChat: Coding0201 | 💬 Telegram: @OAVOProxy | 📧 [email protected]