<aside> 💡

As I prepare for upcoming interviews, this document will serve as a living journal of my progress. I’ll regularly update it with the LeetCode questions I solve, including the strategies I use and step-by-step breakdowns of each solution. My goal is not just to find answers, but to truly understand the underlying patterns and connections between different types of problems.

In addition to solving problems, I’ll focus on identifying recurring techniques and building a strong problem-solving intuition. This journey is about consistent growth, persistence, and learning from every challenge. Let's stay motivated and keep pushing forward—every problem solved is a step closer to success!

More about me

𝕏 Let’s Connect

</aside>

<aside> 🔖

Bookmark this Page!

This page will serve as my central hub for interview prep. As I work through problems, I’ll update this Notion database with detailed notes, strategies, and insights. I’m starting with the LeetCode 75 set and will be expanding it with other high-impact problems from the Blind 75, top interview questions, and frequently asked problems across companies.

The goal is not just to solve—but to master the patterns and build confidence through consistency. Stay tuned for updates as I break down each solution and draw connections between related problems!

If you're new to Python or want to brush up on the basics, click here to review the essential syntax.

</aside>

Leetcode Questions

<aside> 👨‍💻

Python Basics Syntax

<aside> 🥇

String Manipulation

<aside>

# String creation
s = "hello world"
s2 = 'hello world'  # Single or double quotes work the same

# String indexing (0-based)
first_char = s[0]  # 'h'
last_char = s[-1]  # 'd'

# String slicing [start:end:step] (end index is exclusive)
substring = s[0:5]  # "hello"
substring = s[:5]   # "hello" (omitting start defaults to 0)
substring = s[6:]   # "world" (omitting end goes to the end)
reversed_s = s[::-1]  # "dlrow olleh" (negative step reverses)

# String methods
upper_s = s.upper()  # "HELLO WORLD"
lower_s = s.lower()  # "hello world"
capitalized = s.capitalize()  # "Hello world"
split_s = s.split(" ")  # ["hello", "world"]
joined = "-".join(["hello", "world"])  # "hello-world"
replaced = s.replace("hello", "hi")  # "hi world"
stripped = "  text  ".strip()  # "text"

# Check conditions
contains = "hello" in s  # True
starts_with = s.startswith("hello")  # True
ends_with = s.endswith("world")  # True

# String length
length = len(s)  # 1

s = "words"

# Looping over each character
for ch in s:
    print(ch)
# Output:
# w
# o
# r
# d
# s

# 2) Indexing to grab a specific character
first_char = s[0]   # 'w'
third_char = s[2]   # 'r'

</aside>

</aside>

<aside> 🥈

List (Arrays)

<aside>

# List creation
arr = [1, 2, 3, 4, 5]
mixed = [1, "hello", True, 3.14]
empty = []

# List indexing
first = arr[0]  # 1
last = arr[-1]  # 5

# List slicing (works like strings)
sublist = arr[1:4]  # [2, 3, 4]

# List methods
arr.append(6)  # [1, 2, 3, 4, 5, 6]
arr.insert(1, 10)  # [1, 10, 2, 3, 4, 5, 6]
arr.pop()  # Removes and returns last element
arr.pop(0)  # Removes and returns element at index 0
arr.remove(3)  # Removes first occurrence of 3
arr.sort()  # Sorts in-place
arr.reverse()  # Reverses in-place
count = arr.count(2)  # Count occurrences of 2

# List operations
arr1 = [1, 2, 3]
arr2 = [4, 5, 6]
combined = arr1 + arr2  # [1, 2, 3, 4, 5, 6]
doubled = arr1 * 2  # [1, 2, 3, 1, 2, 3]

# List comprehensions
squares = [x**2 for x in range(5)]  # [0, 1, 4, 9, 16]
even_squares = [x**2 for x in range(10) if x % 2 == 0]  # [0, 4, 16, 36, 64]

# Finding elements
index = arr.index(3)  # Find index of first occurrence of 3
exists = 3 in arr  # Check if 3 exists in array

</aside>

</aside>

<aside> 🥉

Dictionaries (Hash maps)

<aside>

# Dictionary creation
d = {"name": "John", "age": 30, "city": "New York"}
empty_dict = {}

# Accessing values
name = d["name"]  # "John"
# Safer access with get (returns None if key doesn't exist)
age = d.get("age")  # 30
country = d.get("country")  # None
country = d.get("country", "USA")  # "USA" (default value)

# Modifying dictionaries
d["email"] = "[email protected]"  # Add new key-value pair
d["age"] = 31  # Update existing value
d.update({"phone": "123-456-7890", "age": 32})  # Update multiple keys

# Dictionary methods
keys = d.keys()  # dict_keys(['name', 'age', 'city', 'email'])
values = d.values()  # dict_values(['John', 32, 'New York', '[email protected]'])
items = d.items()  # dict_items([('name', 'John'), ('age', 32), ...])
d.pop("age")  # Removes and returns value for key "age"
d.popitem()  # Removes and returns last inserted item as tuple

# Check if key exists
has_name = "name" in d  # True

# Dictionary comprehension
squares_dict = {x: x**2 for x in range(5)}  # {0: 0, 1: 1, 2: 4, 3: 9, 4: 16}

</aside>

</aside>

<aside> 4️⃣

Sets

<aside>

# Set creation
s = {1, 2, 3, 4, 5}
s = set([1, 2, 2, 3, 4])  # {1, 2, 3, 4} (removes duplicates)
empty_set = set()  # Note: {} creates an empty dictionary, not a set

# Set methods
s.add(6)  # Add element
s.remove(3)  # Remove element (raises error if not found)
s.discard(10)  # Remove if present (no error if not found)
s.pop()  # Remove and return arbitrary element

# Set operations
s1 = {1, 2, 3}
s2 = {3, 4, 5}
union = s1 | s2  # {1, 2, 3, 4, 5}
intersection = s1 & s2  # {3}
difference = s1 - s2  # {1, 2}
symmetric_diff = s1 ^ s2  # {1, 2, 4, 5}

# Check membership
contains = 2 in s1  # True

</aside>

</aside>

<aside> ✋

Loops

<aside>

# For loop with range
for i in range(5):  # 0, 1, 2, 3, 4
    print(i)

# For loop with range (start, end, step)
for i in range(1, 10, 2):  # 1, 3, 5, 7, 9
    print(i)

# For loop with iterable
for item in [1, 2, 3, 4]:
    print(item)

# For loop with index using enumerate
for index, value in enumerate(["a", "b", "c"]):
    print(index, value)  # 0 a, 1 b, 2 c

# For loop with dictionary
for key in d:
    print(key, d[key])

# Alternate dictionary iteration
for key, value in d.items():
    print(key, value)

# While loop
i = 0
while i < 5:
    print(i)
    i += 1

</aside>

</aside>

<aside> 6️⃣

Common Data Structures

<aside>

# Stack (using list)
stack = []
stack.append(1)  # Push
stack.append(2)
top = stack[-1]  # Peek top element
popped = stack.pop()  # Pop (removes and returns)

# Queue (using collections.deque for O(1) operations)
from collections import deque
queue = deque()
queue.append(1)  # Enqueue
queue.append(2)
front = queue[0]  # Peek front element
dequeued = queue.popleft()  # Dequeue

# Priority Queue (Min Heap)
import heapq
heap = []
heapq.heappush(heap, 3)  # Push element
heapq.heappush(heap, 1)
heapq.heappush(heap, 2)
min_val = heap[0]  # Peek minimum (doesn't remove)
min_val = heapq.heappop(heap)  # Pop minimum

# Counter (frequency counter)
from collections import Counter
counter = Counter([1, 2, 2, 3, 3, 3])  # {1: 1, 2: 2, 3: 3}
most_common = counter.most_common(2)  # [(3, 3), (2, 2)]

</aside>

</aside>

<aside> 7️⃣

Control Flow and Conditions

<aside>

# If-else statements
if x > 0:
    print("Positive")
elif x < 0:
    print("Negative")
else:
    print("Zero")

# Ternary operator
result = "Even" if x % 2 == 0 else "Odd"

# Boolean operators
if x > 0 and y > 0:
    print("Both positive")
if x > 0 or y > 0:
    print("At least one positive")
if not x > 0:
    print("Not positive")

</aside>

</aside>

<aside> 🎱

Functions

<aside>

# Basic function
def add(a, b):
    return a + b

# Function with default parameters
def greet(name="World"):
    return f"Hello, {name}!"

# Function with multiple returns
def min_max(arr):
    return min(arr), max(arr)

# Lambda functions (anonymous functions)
square = lambda x: x * x

</aside>

</aside>

<aside> 9️⃣

Useful Built-in Functions

<aside>

# Math operations
minimum = min(1, 2, 3)  # 1
maximum = max(1, 2, 3)  # 3
absolute = abs(-5)  # 5
power = pow(2, 3)  # 8 (same as 2**3)
rounded = round(3.7)  # 4

# Conversion
integer = int("123")  # 123
string = str(123)  # "123"
floating = float("3.14")  # 3.14

# Sorting
sorted_list = sorted([3, 1, 2])  # [1, 2, 3]
sorted_desc = sorted([3, 1, 2], reverse=True)  # [3, 2, 1]
sorted_by_len = sorted(["apple", "banana", "cherry"], key=len)  # ["apple", "cherry", "banana"]

# List operations
total_sum = sum([1, 2, 3])  # 6
any_true = any([False, True, False])  # True
all_true = all([True, True, True])  # True

</aside>

</aside>

</aside>