Skip to content

Instantly share code, notes, and snippets.

View storys08-cloud's full-sized avatar

LazyUnicorn storys08-cloud

  • Joined Sep 6, 2025
View GitHub Profile
@storys08-cloud
storys08-cloud / gist:3e6baa6669cf160929c1b34a4f6aab70
Created October 6, 2025 05:03
Linked List: Add Two Numbers with Carry
# 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.
"""
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.
# ==========================================
# 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 €
@storys08-cloud
storys08-cloud / gist:287dd3e3be872b542e91fc67872b465d
Last active October 3, 2025 04:46
Fire Escape Problem – BFS & A* Example
"""
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)