One idea
Use the simplest structure that gives the operation cost you need. Arrays and strings are good for ordered scans. Maps and sets are good when fast lookup or frequency matters.
When to pick what
Pick an array when you need index access, sorting, prefix sums, two pointers, or a sliding window. In Python, use list. In JavaScript, use Array.
Pick a string when the input is text, but remember many strings are immutable. If you build many characters step by step, collect pieces in an array or list, then join.
Maps and sets
Pick a map when each key has a value: count, last seen index, parent, score, or group. Python uses dict. JavaScript uses Map or a plain object for simple string keys.
Pick a set when you only care whether something exists. Use it for duplicate checks, visited items, and membership tests.
Interview pattern check
Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.
0 of 4 done
Example file
Add one clean problem to your kit today: first non-repeating character. It shows why a map is better than scanning the string again and again.
# arrays_strings_maps_sets/first_non_repeating.py
def first_non_repeating(s: str) -> str:
freq = {}
for ch in s:
freq[ch] = freq.get(ch, 0) + 1
for ch in s:
if freq[ch] == 1:
return ch
return ""
def test_first_non_repeating():
assert first_non_repeating("aabbcdd") == "c"
assert first_non_repeating("leetcode") == "l"
assert first_non_repeating("aabb") == ""
assert first_non_repeating("") == ""Common mistake
Do not say “hash map is always faster.” It is faster for lookup and counting on average, but it uses extra memory and loses natural order unless you manage order separately.
Also avoid sorting when the original order matters. Sorting may reduce one cost, but it changes positions and can break the answer.
Use AI well
Ask AI for three approaches, not just code. Example prompt: “Solve this using array scan, sorting, and hash map. Compare time and space. Then give Python tests.”
Check the output yourself. Look for wrong edge cases, hidden sorting, missing empty input, and claims like O(1) space when a map grows with n.
Do this now
Do each one yourself, then tap it to tick it off. The ticks are only a checklist for you: they are not marked or scored.
0 of 5 done