Here’s a detailed cheat sheet for Amazon’s SDE Online Assessment, designed to be as comprehensive and useful as possible. It covers common coding patterns, problem types, data structures, algorithms, and useful Python snippets.


1. Arrays and Strings

Common Patterns:

def sliding_window(arr, k):
    window_sum = sum(arr[:k])
    max_sum = window_sum
    for i in range(k, len(arr)):
        window_sum += arr[i] - arr[i - k]
        max_sum = max(max_sum, window_sum)
    return max_sum
def two_pointers(arr):
    left, right = 0, len(arr) - 1    while left < right:
        # Use pointers to compare elements        left += 1        right -= 1

String Manipulation Tricks:


2. Linked Lists

Common Patterns:

def detect_cycle(head):
    slow, fast = head, head
    while fast and fast.next:
        slow = slow.next        fast = fast.next.next        if slow == fast:
            return True    return False
def reverse_linked_list(head):
    prev, curr = None, head
    while curr:
        next_node = curr.next        curr.next = prev
        prev = curr
        curr = next_node
    return prev