Skip to main content

Data Types

Absolutely β€” knowing your core data types inside and out is essential for LeetCode and coding interviews. These are the types you’ll see constantly and will use to build efficient solutions.

Here’s a curated list of the must-know data types for LeetCode β€” including how to use them, when to choose them, and a one-liner to remember what they’re best at.


🧠 LeetCode Data Types You Should Know (Python)


βœ… 1. int – Whole numbers

Used for counting, math, binary, etc.

n = 42

πŸ§ͺ Use cases:

  • Loops, math, binary search, bit manipulation


βœ… 2. float – Decimal numbers

Used rarely, but important for precision-sensitive problems.

pi = 3.14

πŸ§ͺ Watch out for rounding errors.


βœ… 3. str – Strings

πŸ”₯ High-frequency on LeetCode

s = "leetcode"

πŸ§ͺ Know:

  • s[::-1] – reverse

  • s.split() – split by whitespace

  • s.isalnum() – alphanumeric check

  • ord(c), chr(n) – ASCII value


βœ… 4. list – Ordered, mutable collection

πŸ”₯ Most used structure in LeetCode

arr = [1, 2, 3]

πŸ§ͺ Know:

  • arr.append(x)

  • arr.pop(), arr.pop(0)

  • arr[::-1]

  • arr.sort() vs sorted(arr)

  • Slicing, binary search, sliding window


βœ… 5. tuple – Ordered, immutable collection

Used for keys in sets/dicts or returning multiple values.

t = (1, 2)

πŸ§ͺ Know:

  • x, y = t

  • Useful as hashable keys: visited[(x, y)] = True


βœ… 6. set – Unordered, unique items

πŸ”‘ Great for fast lookup and duplicates

s = set([1, 2, 3])

πŸ§ͺ Know:

  • x in s β†’ O(1)

  • set(list) removes duplicates

  • Set operations: union, intersection, difference


βœ… 7. dict – Key-value pairs

πŸ”₯ Critical for hash maps / fast lookups

d = {"a": 1, "b": 2}

πŸ§ͺ Know:

  • d.get(k, default)

  • defaultdict(list)

  • Frequency count: Counter(s)

  • Keys/values/items iteration


βœ… 8. collections.deque – Double-ended queue

⚑ Fast append and popleft() β†’ great for BFS

from collections import deque
q = deque([1, 2])
q.append(3)
q.popleft()

βœ… 9. heapq / Min Heap (via list)

πŸ’‘ Use for priority queue, top K elements

import heapq
h = [5, 3, 8]
heapq.heapify(h)
heapq.heappop(h)

πŸ§ͺ Python only has min-heaps β€” invert values for max-heap.


βœ… 10. collections.Counter – Fast frequency counting

from collections import Counter
c = Counter("aabbcc")

πŸ§ͺ Useful for:

  • Anagram check

  • Majority element

  • Multiset behavior


🧠 TL;DR: Memorize These for LeetCode

Type What it's good for
int Counting, math
float Precision, rarely needed
str Manipulation, parsing, search
list Arrays, stacks, sliding window
tuple Hashable keys, return multiple items
set Uniqueness, fast lookup
dict Key-value, counting, hash maps
deque BFS, queue (O(1) pops)
heapq Priority queue, top K problems
Counter Fast frequency counting

Would you like:

  • Anki cards for this?

  • Daily drills where you implement key operations from memory?

  • A printable reference sheet or PDF?