Solve Algorithmic Challenges in Online Coding Assessments
Company: Amazon
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates proficiency in fundamental algorithmic problem-solving, specifically array manipulation, string processing, and the use of basic data structures along with performance and complexity reasoning.
Two Sum
Constraints
- 2 <= len(nums) <= 10^4
- -10^9 <= nums[i] <= 10^9
- -10^9 <= target <= 10^9
- Exactly one valid answer exists.
Examples
Input: ([2, 7, 11, 15], 9)
Expected Output: [0, 1]
Explanation: nums[0] + nums[1] = 2 + 7 = 9.
Input: ([3, 2, 4], 6)
Expected Output: [1, 2]
Explanation: nums[1] + nums[2] = 2 + 4 = 6; note nums[0]=3 alone cannot reuse itself.
Hints
- A brute-force O(n^2) approach checks every pair, but you can do better.
- As you iterate, store each number's index in a hash map.
- For each number, check whether target - number is already in the map; if so you have your pair.
Longest Substring Without Repeating Characters
Constraints
- 0 <= len(s) <= 5 * 10^4
- s consists of English letters, digits, symbols, and spaces.
Examples
Input: ("abcabcbb",)
Expected Output: 3
Explanation: The longest unique substring is "abc" with length 3.
Input: ("bbbbb",)
Expected Output: 1
Explanation: Every character repeats; the best window is a single "b".
Hints
- Maintain a sliding window [start, i] that always contains only unique characters.
- Track the most recent index where each character was seen in a hash map.
- When you encounter a repeat that lies inside the current window, jump start to one past its previous index.