
This was an Amazon Intern OA on HackerRank with a 70-minute limit. Both questions were fundamental, but clean handling of details mattered.
Q1: Return the index of the first unique character
Interview-ready wording
I solve it in two passes:
- First pass: count frequency of each character (HashMap or fixed array).
- Second pass: scan in original order and return the first index whose frequency is exactly 1.
If none exists, return the fallback required by the statement (commonly -1).
Complexity
- Time:
O(n) - Space:
O(Σ)(constant if alphabet is fixed)
Q2: Count distinct pairs whose sum equals target

Interview-ready wording
For each number x:
- Compute
need = target - x - If
needhas been seen before, we found a valid pair - To deduplicate, store only the smaller value in that pair
At the end, the number of distinct stored smaller values equals the number of distinct valid pairs.
This works well because the same numeric pair (e.g., 2 and 7) always maps to the same dedup key (2) regardless of encounter order.
Complexity
- Time:
O(n) - Space:
O(n)
Common mistakes under time pressure
- Returning any unique character instead of the first one
- Returning the character instead of its index in Q1
- Detecting two-sum hits in Q2 but forgetting pair deduplication
- Double-counting the same pair due to different encounter order
One-line takeaway
This OA set is less about advanced algorithms and more about stable basics, clean edge handling, and clear dedup logic.
If you are preparing for Amazon Intern OA (HackerRank), feel free to reach out for similar high-frequency variants and explanation templates.
Further Reading (External Links)
Need real interview questions? Contact WeChat Coding0201: Get Questions.
Contact
Email: [email protected]
Telegram: @OAVOProxy