Stock Trading Problems: Cooldown Period and Transaction Fee

Problem 309: Best Time to Buy and Sell Stock with Cooldown Given an integer array prices where prices[i] represents the stock price on day i. Design an algorithm to calculate the maximum profit under the constraint that you cannot buy stock on the day after selling (one-day cooldown period). Dynamic Programming Approach The key to solving this ...

Posted on Sat, 03 Oct 2026 16:03:59 +0000 by kevintynfron

Checking if an Array Can Be Split into Two Distinct Halves

Given an integer array nums of even length, you need to split it into two arrays, nums1 and nums2, such that: nums1.length == nums2.length == nums.length / 2. nums1 contains distinct elements. nums2 also contains distinct elements. If such a split is posssible, return true; otherwise, return false. Examples Example 1: Input: nums = [1,1,2,2,3 ...

Posted on Fri, 02 Oct 2026 16:39:13 +0000 by rfighter

Advanced Techniques for Solving Linked List Problems

Intersection of Two Linked ListsTo determine the node where two singly-linked lists intersect, one can utilize a dual-pointer technique that accounts for the difference in lengths. By swapping the pointers when they reach the end of their respective lists, both pointers effectively traverse the combined length of the two lists. This synchroniza ...

Posted on Fri, 02 Oct 2026 16:18:39 +0000 by Scifa

Dynamic Programming Solution for Edit Distance Problem

Problem Statement Given two strings source and target, return the minimum number of opreations required to convert source in to target. You can perform the following three operations on a string: Insert a character Delete a character Replace a character Example 1: Input: source = "horse", target = "ros" Output: 3 horse -& ...

Posted on Wed, 30 Sep 2026 16:04:27 +0000 by pedrokas

Finding the Minimum Divisor to Keep the Sum Below a Threshold

The objective is to determine the smallest positive integer divisor such that the sum of the divisions of an integer array does not exceed a given threshold. Each division operation must be rounded up to the nearest integer. Given the constraints, a linear search is inefficient, making binary search the optimal approach for locating the minimum ...

Posted on Sat, 26 Sep 2026 16:53:07 +0000 by scott56hannah

Dynamic Programming Path Problems: From Grid Traversal to Minimum Health Requirements

A robot starts at the top-left corner of an m × n grid and must reach the bottom-right corner. It can only move right or down. How many distinct paths exist? Use dynamic programming where dp[i][j] reprseents the number of ways to reach cell (i, j) from the origin. Transition: dp[i][j] = dp[i-1][j] + dp[i][j-1] Base case: Initialize dp[0][1] = 1 ...

Posted on Sat, 26 Sep 2026 16:23:47 +0000 by leoden

Minimum Flips to Achieve Target Bulb Configuration

1529. Bulb Switcher IV There are n light bulbs arranged in a row from left to right, numbered from 0 to n-1. Initially, all bulbs are turned off. Your task is to make the state of the bulbs match the target configuration, where target[i] = 1 means the i-th bulb is on, and target[i] = 0 means the i-th bulb is off. You have a switch that can flip ...

Posted on Fri, 25 Sep 2026 16:47:54 +0000 by pkallberg21

Two-Pointer Techniques for Array Manipulation Algorithms

In-Place Element Removal When tasked with filtering out specific values from an array in-place, allocating additional memory is often restricted. The two-pointer method provides an elegant solution by separating the reading and writing processes. Strategy: Read and Write Pointers We initialize two distinct indices: a write_idx to track the posi ...

Posted on Mon, 21 Sep 2026 16:38:55 +0000 by jacobelias

Essential Binary-Tree Algorithms and Their Implementations

In-Order Traversal Recursive List<Integer> inorder(TreeNode node) { List<Integer> out = new ArrayList<>(); walk(node, out); return out; } void walk(TreeNode cur, List<Integer> acc) { if (cur == null) return; walk(cur.left, acc); acc.add(cur.val); walk(cur.right, acc); } Iterative (Single Sta ...

Posted on Mon, 21 Sep 2026 16:25:53 +0000 by otterbield

Binary Search on Rotated Sorted Arrays

Let's explore 4 problems related to searching in rotated sorted arrays: LeetCode 33: Search in Rotated Sorted Array LeetCode 81: Search in Rotated Sorted Array II LeetCode 153: Find Minimum in Rotated Sorted Array LeetCode 154: Find Minimum in Rotated Sorted Array II These can be categorized into three groups: 33, 81: Searching for a specifi ...

Posted on Sun, 20 Sep 2026 16:37:14 +0000 by frost