Arrays, strings, and hashing consistently account for more than 60% of all coding questions asked in SDE1 and entry-level FAANG loops. If you are a fresher or new grad targeting Amazon SDE1, Google L3, Meta E3, or a product company engineering role, these three topics are where your preparation needs to be sharpest.
This blog covers the most frequently asked problems from this category, with verified solutions, full complexity analysis, and the approach reasoning interviewers expect you to narrate out loud.
Every solution here has been verified for correctness. Code is in Python.
What SDE1 Coding Rounds Actually Look Like
Before the problems, context on what you are walking into:
Amazon SDE1: Two LeetCode-style problems in 70–90 minutes on the OA. One medium array/string problem, one medium tree or graph problem. Virtual interview rounds add live follow-ups on your approach and edge cases.
Google L3: Two problems in 45 minutes per round. Difficulty ranges from easy-medium to medium. Interviewers expect time and space complexity stated unprompted at the end of every solution.
Meta E3 / Product companies: Two problems per round. Speed matters, aim to complete each problem in under 25 minutes to leave room for follow-ups.
The pattern across all SDE1 loops: Easy-Medium to Medium difficulty, emphasis on clean code and clear communication, not algorithmic tricks.
Problem 1: Two Sum
Difficulty: Easy. Asked at: Amazon, Google, Meta, Apple, extremely high frequency at SDE1 level. LeetCode: #1
Problem Statement
Given an array of integers nums and an integer target, return the indices of the two numbers that add up to target. You may assume exactly one solution exists, and you may not use the same element twice.
Example:
Input: nums = [2, 7, 11, 15], target = 9
Output: [0, 1]
Explanation: nums[0] + nums[1] = 2 + 7 = 9
Approach
The brute-force approach checks every pair - O(n²) time. We can do better.
As we iterate through the array, for each element x, we need to know if target - x already exists in what we've seen so far. A hash map gives us O(1) lookup for this check.
Walk through the array once. At each index i, compute complement = target - nums[i]. If complement is already in the hash map, we found our pair, return both indices. If not, store nums[i] → i in the map and continue.
Solution
python
def two_sum(nums, target):
seen = {} # value -> index
for i, num in enumerate(nums):
complement = target - num
if complement in seen:
return [seen[complement], i]
seen[num] = i
return [] # problem guarantees a solution exists, but safe to handle
Trace Through the Example
nums = [2, 7, 11, 15], target = 9
i=0: num=2, complement=7. Not in seen. Store {2: 0}
i=1: num=7, complement=2. Found in seen at index 0. Return [0, 1] ✓
Complexity
- Time: O(n) - single pass through the array
- Space: O(n) - hash map stores at most n entries
Edge Cases to Mention in Interview
- Negative numbers: handled correctly, complement arithmetic works for negatives
- Duplicate values like
[3, 3]with target6: handled correctly, we store the first 3 before checking, so when we see the second 3, we find the first one in the map
Problem 2: Longest Substring Without Repeating Characters
Difficulty: Medium. Asked at: Amazon, Google, Meta, one of the most reported SDE1 questions. LeetCode: #3
Problem Statement
Given a string s, find the length of the longest substring that contains no repeating characters.
Example:
Input: s = "abcabcbb"
Output: 3
Explanation: "abc" is the longest substring without repeating characters
Approach
This is a sliding window problem. We maintain a window [left, right] where all characters are unique. As we expand right, if we encounter a character already in the window, we shrink from left until the duplicate is removed. A hash map tracks each character's most recent index so we can jump left directly rather than shrinking one by one.
Solution
python
def length_of_longest_substring(s):
char_index = {} # char -> most recent index
left = 0
max_length = 0
for right, char in enumerate(s):
# If char is in window, move left past its previous occurrence
if char in char_index and char_index[char] >= left:
left = char_index[char] + 1
char_index[char] = right
max_length = max(max_length, right - left + 1)
return max_length
Trace Through the Example
s = "abcabcbb"
right=0, char='a': not in window. char_index={'a':0}. length=1
right=1, char='b': not in window. char_index={'a':0,'b':1}. length=2
right=2, char='c': not in window. char_index={'a':0,'b':1,'c':2}. length=3
right=3, char='a': 'a' at index 0 >= left(0). Move left to 1. char_index={'a':3,...}. length=3
right=4, char='b': 'b' at index 1 >= left(1). Move left to 2. char_index={'b':4,...}. length=3
right=5, char='c': 'c' at index 2 >= left(2). Move left to 3. char_index={'c':5,...}. length=3
right=6, char='b': 'b' at index 4 >= left(3). Move left to 5. length=2
right=7, char='b': 'b' at index 6 >= left(5). Move left to 7. length=1
Final answer: 3 ✓
Complexity
- Time: O(n) - each character is visited at most twice (once by right, once by left)
- Space: O(min(n, m)) - where m is the size of the character set (26 for lowercase letters)
Why char_index[char] >= left Matters
Without this check, a character that was seen before the current window would incorrectly push left backward. This condition ensures we only respond to characters that are actually inside the current window.
Problem 3: Valid Anagram
Difficulty: Easy. Asked at: Amazon, Google, frequently appears in OA and phone screens. LeetCode: #242
Problem Statement
Given two strings s and t, return True if t is an anagram of s, and False otherwise. An anagram contains the same characters in the same frequencies, in any order.
Example:
Input: s = "anagram", t = "nagaram"
Output: True
Input: s = "rat", t = "car"
Output: False
Approach
Two strings are anagrams if and only if they have identical character frequency counts. We can count characters in s, then decrement those counts using t. If any count goes negative, or counts remain non-zero at the end, they are not anagrams.
A cleaner approach: use Python's Counter directly, or use a single frequency array of size 26 for lowercase letters.
Solution
python
def is_anagram(s, t):
if len(s) != len(t):
return False
count = [0] * 26 # for lowercase a-z only
for char in s:
count[ord(char) - ord('a')] += 1
for char in t:
count[ord(char) - ord('a')] -= 1
return all(c == 0 for c in count)
Complexity
- Time: O(n) - two passes through strings of length n
- Space: O(1) - the count array is always size 26, regardless of input size
Follow-up Interviewers Ask
"What if the inputs contain Unicode characters, not just lowercase letters?"
Use a hash map (dictionary) instead of the fixed-size array, so we can handle any character set:
python
def is_anagram_unicode(s, t):
if len(s) != len(t):
return False
from collections import Counter
return Counter(s) == Counter(t)
Problem 4: Group Anagrams
Difficulty: Medium. Asked at: Amazon, Google, Meta, high frequency at SDE1 levelLeetCode: #49
Problem Statement
Given an array of strings, group the anagrams together. The order of output does not matter.
Example:
Input: strs = ["eat","tea","tan","ate","nat","bat"]
Output: [["bat"],["nat","tan"],["ate","eat","tea"]]
Approach
Anagrams share the same sorted form. "eat", "tea", and "ate" all sort to "aet". Use this sorted string as the key in a hash map, grouping strings that share the same key.
Solution
python
from collections import defaultdict
def group_anagrams(strs):
anagram_map = defaultdict(list)
for word in strs:
key = tuple(sorted(word)) # sorted tuple as hashable key
anagram_map[key].append(word)
return list(anagram_map.values())
Trace Through the Example
"eat" → sorted → "aet" → anagram_map["aet"] = ["eat"]
"tea" → sorted → "aet" → anagram_map["aet"] = ["eat", "tea"]
"tan" → sorted → "ant" → anagram_map["ant"] = ["tan"]
"ate" → sorted → "aet" → anagram_map["aet"] = ["eat", "tea", "ate"]
"nat" → sorted → "ant" → anagram_map["ant"] = ["tan", "nat"]
"bat" → sorted → "abt" → anagram_map["abt"] = ["bat"]
Output: [["eat","tea","ate"], ["tan","nat"], ["bat"]] ✓
Complexity
- Time: O(n × k log k) - where n is number of strings, k is max string length (sorting each string costs k log k)
- Space: O(n × k) - storing all strings in the map
Problem 5: Best Time to Buy and Sell Stock
Difficulty: Easy. Asked at: Amazon, Google, Apple, very high frequency. LeetCode: #121
Problem Statement
You are given an array prices where prices[i] is the price of a stock on day i. You want to maximise profit by choosing a single day to buy and a single day to sell after the buy day. Return the maximum profit. If no profit is possible, return 0.
Example:
Input: prices = [7, 1, 5, 3, 6, 4]
Output: 5
Explanation: Buy on day 2 (price=1), sell on day 5 (price=6). Profit = 6-1 = 5.
Approach
We want to find the maximum difference prices[j] - prices[i] where j > i. We do not need to check every pair.
Iterate through prices while tracking the minimum price seen so far. At each step, compute the profit if we sold today (current price minus minimum seen so far). Track the maximum profit across all days.
Solution
python
def max_profit(prices):
min_price = float('inf')
max_profit = 0
for price in prices:
if price < min_price:
min_price = price
profit = price - min_price
if profit > max_profit:
max_profit = profit
return max_profit
Trace Through the Example
prices = [7, 1, 5, 3, 6, 4]
price=7: min=7, profit=0, max_profit=0
price=1: min=1, profit=0, max_profit=0
price=5: min=1, profit=4, max_profit=4
price=3: min=1, profit=2, max_profit=4
price=6: min=1, profit=5, max_profit=5
price=4: min=1, profit=3, max_profit=5
Output: 5 ✓
Complexity
- Time: O(n) - single pass
- Space: O(1)- only two variables maintained
Problem 6: Contains Duplicate
Difficulty: Easy. Asked at: Amazon, Google, common warm-up or OA first question. LeetCode: #217
Problem Statement
Given an integer array nums, return True if any value appears at least twice, and False if all elements are distinct.
Example:
Input: nums = [1, 2, 3, 1]
Output: True
Approach
Add elements to a set as we iterate. If we encounter an element already in the set, a duplicate exists. Return False if we finish without finding one.
Solution
python
def contains_duplicate(nums):
seen = set()
for num in nums:
if num in seen:
return True
seen.add(num)
return False
Complexity
- Time: O(n)
- Space: O(n)
One-liner alternative (acceptable in interviews if you explain it):
python
def contains_duplicate(nums):
return len(nums) != len(set(nums))
Problem 7: Product of Array Except Self
Difficulty: Medium. Asked at: Amazon, Google, Meta, very frequently reported at SDE1 level. LeetCode: #238
Problem Statement
Given an integer array nums, return an array output where output[i] is the product of all elements in nums except nums[i]. You must solve it without using division, in O(n) time.
Example:
Input: nums = [1, 2, 3, 4]
Output: [24, 12, 8, 6]
Approach
For each index i, the answer is: (product of all elements to the left of i) × (product of all elements to the right of i).
We build this in two passes:
Pass 1 (left to right): result[i] = product of all elements to the left of i. For index 0, left product = 1 (no elements to the left).
Pass 2 (right to left): Multiply each result[i] by the running right product so far.
Solution
python
def product_except_self(nums):
n = len(nums)
result = [1] * n
# Pass 1: result[i] = product of all elements left of i
left_product = 1
for i in range(n):
result[i] = left_product
left_product *= nums[i]
# Pass 2: multiply result[i] by product of all elements right of i
right_product = 1
for i in range(n - 1, -1, -1):
result[i] *= right_product
right_product *= nums[i]
return result
Trace Through the Example
nums = [1, 2, 3, 4]
After Pass 1 (left products):
result = [1, 1, 2, 6]
(index 0: no left → 1; index 1: left of 1 → 1; index 2: 1×2=2; index 3: 1×2×3=6)
After Pass 2 (multiply right products):
i=3: result[3] = 6 × 1 = 6; right_product = 1×4 = 4
i=2: result[2] = 2 × 4 = 8; right_product = 4×3 = 12
i=1: result[1] = 1 × 12 = 12; right_product = 12×2 = 24
i=0: result[0] = 1 × 24 = 24; right_product = 24×1 = 24
Output: [24, 12, 8, 6] ✓
Complexity
- Time: O(n) - two passes
- Space: O(1) extra space (the output array itself is not counted as extra space per the problem)
How to Answer These in an Actual Interview
The difference between a pass and a fail on these problems is rarely whether you get the correct answer. It's how you got there.
What interviewers at Amazon SDE1 and Google L3 consistently report looking for:
Before you code:
- Restate the problem and confirm your understanding
- Ask about edge cases: empty input, negative numbers, duplicates, single element
- Name the approach you're going to use and why
While you code:
- Narrate your decisions: "I'm using a hash map here because we need O(1) lookup"
- Don't go silent for more than 30 seconds
- Write clean, readable code, variable names matter
After you code:
- State time and space complexity unprompted (Google interviewers expect this without being asked)
- Trace through at least one example
- Mention edge cases you handled and any you didn't
What Comes Next in an SDE1 Loop
Arrays, strings, and hashing form the foundation. The next category you will be tested on in SDE1 loops is trees and linked lists, pointer manipulation, traversal, and structural reasoning.
If you want to practice these problems in a live, pressure-tested environment, with a real engineer giving you structured feedback on both your solution and your communication, book a mock interview on Intervue.io. The feedback after each session tells you specifically what to fix before your actual loop.
Summary
The most frequently asked SDE1 coding problems in arrays, strings, and hashing at FAANG and product companies:
- Two Sum: hash map for O(1) complement lookup
- Longest Substring Without Repeating Characters: sliding window with character index tracking
- Valid Anagram: frequency counting with a fixed-size array
- Group Anagrams: sorted string as hash map key
- Best Time to Buy and Sell Stock: track minimum price, compute max profit in one pass
- Contains Duplicate: set for O(1) membership check
- Product of Array Except Self: two-pass prefix/suffix product, no division
Master these patterns. Practice them under a timer. And when you are 3–4 weeks from your actual loop, practice them with a real engineer watching.



