Calculating Capital Gains and Losses from Stock Transactions
The Stocks table schema is defined as follows:
Column Name
Type
stock_name
varchar
operation
enum
operation_day
int
price
int
The primary key for this table is the combination of stock_name and operation_day. The operation column is an enumeration containing ('Buy', 'Sell'). Each row represents a transaction made on a specific s ...
Posted on Tue, 02 Jun 2026 18:08:55 +0000 by hush2
Maximum Sum Divisible by Three
Given an integer array nums, find and return the maximum sum of elements that is divisible by three.
Examples
Example 1:
Input: nums = [3,6,5,1,8]
Output: 18
Explanation: Choose numbers 3, 6, 1, and 8. Their sum is 18 (the maximum sum divisible by three).
Example 2:
Input: nums = [4]
Output: 0
Explanation: 4 is not divisible by 3, so no number ...
Posted on Tue, 02 Jun 2026 17:22:57 +0000 by JamesThePanda
Singly Linked List Reversal: Iterative and Recursive Solutions for LeetCode 206
Problem Statement
Given the head of a singly linked list, reverse the order of all nodes in the list and return the head of the reversed list.
Sample Input 1:
head = [1,2,3,4,5]
Sample Output 1:
[5,4,3,2,1]
Sample Input 2:
head = [1,2]
Sample Output 2:
[2,1]
Sample Input 3:
head = []
Sample Output 3:
[]
Constraints:
The number of nodes i ...
Posted on Sun, 31 May 2026 19:45:10 +0000 by cowboysdude
Linked List Algorithms from Code Thinking Record
Table of Contents
Introduction
Remove Linked List Elements (LeetCode--203)
Design Linked List (LeetCode--707)
Reverse Linked List (LeetCode--206)
Swap Nodes in Pairs (LeetCode--24)
Remove Nth Node From End of List (LeetCode--19)
Linked List Cycle II (LeetCode--142)
Introduction
Following the Code Thinking Record series, this article explores ...
Posted on Sun, 31 May 2026 19:14:58 +0000 by gingerboy101
Dynamic Programming: Solving Multi-State Problems
The Massage Therapist Scheduling Problem
Problem link: https://leetcode.cn/problems/the-masseuse-lcci/
A renowned massage therapist receives a continuous stream of appointment requests. Each appointment can be accepted or declined. Due to the need for rest periods between sessions, she cannot accept consecutive appointments. Given a sequence of ...
Posted on Sat, 30 May 2026 19:39:23 +0000 by stelthius
Dynamic Programming: Core Concepts and Algorithmic Implementations
Understanding Dynamic Programming
Dynamic programming (DP) is an optimization technique used to solve complex problems by breaking them into simpler subproblems. It stores the results of subproblems to avoid redundant computations, thereby improving efficiency. This article explores fundamental DP concepts and implementations through various al ...
Posted on Wed, 20 May 2026 00:48:10 +0000 by saint959
Fundamentals of the 0-1 Knapsack Problem and Partition Equal Subset Sum Solution
Core Principles of the 0-1 Knapsack Problem
The 0-1 Knapsack Problem serves as the foundation for various packing challenges. Given a set of items with specific weights and values, the objective is to maximize value while not exceeding a given capacity constraint. Each item can be included at most once.
Dynamic Programming Solution
We use a DP ...
Posted on Sun, 17 May 2026 06:53:50 +0000 by stickynote427
Solving Longest Valid Parentheses, Trapping Rain Water, and Wildcard Matching Problems
Longest Valid Parentheses
Given a string containing only '(' and ')', find the length of the longest valid (well-formed and contiguous) parentheses substring.
Dynamic Programming Solution
Define dp[i] as the length of the longest valid parentheses ending at position i. To each character at index i:
If s[i] is '(', set dp[i] = 0
If s[i] is ')', ...
Posted on Sat, 16 May 2026 08:12:44 +0000 by mitchell_1078
LeetCode 62: Unique Paths (Dynamic Programming, Combinatorics)
Problem Description
A robot is located at the top - left corner of an m x n grid (marked 'Start'). The robot can only move either down or right at any point. The goal is to reach the bottom - right corner (marked 'Finish'). We need to determine the number of unique paths possible.
Examples
Example 1:
Input: rows = 3, cols = 7
Output: 28
Exampl ...
Posted on Sat, 16 May 2026 05:47:43 +0000 by ansarka
LeetCode Problem Solutions: Sliding Window and Hash Table Techniques
Trpaping Rain Water Problem
Given an array representing elevation maps, this problem calculates how much water can be trapped between bars after raining.
vector<int> leftMax(n, 0);
vector<int> rightMax(n, 0);
if (n == 0) return 0;
leftMax[0] = height[0];
rightMax[n-1] = height[n-1];
for (int i = 1; i < n; ++i) {
leftMax[i] = ...
Posted on Fri, 15 May 2026 23:00:45 +0000 by jck