This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Definition for singly-linked list node. | |
class ListNode: | |
def __init__(self, val=0, next=None): | |
self.val = val | |
self.next = next | |
class Solution: | |
def addTwoNumbers(self, l1, l2): | |
""" | |
Add two numbers represented by linked lists in reverse order. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Problem: Two Sum | |
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. | |
You may assume that each input would have exactly one solution, | |
and you may not use the same element twice. | |
You can return the answer in any order. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ========================================== | |
# Knapsack Problem Example | |
# Context: A thief has a backpack with a max weight of 10 kg | |
# There is a table full of valuable items | |
# The goal: maximize the total value without exceeding the weight limit | |
# Items: | |
# A: 7 kg, 1000 € | |
# B: 2 kg, 400 € | |
# C: 3 kg, 500 € | |
# D: 4 kg, 600 € |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Fire Escape Problem – BFS & A* Example | |
Example scenario: | |
- Grid: 6 cells wide × 3 cells high | |
- Each cell = a room | |
- Player: starts at top-left (0,2) | |
- Fire: starts at top-right (5,2) | |
- Exit: bottom-right (5,0) | |
- Walls: (2,1), (3,1) |