Binary Search Tree Pair Sum Algorithm Implementation

Problem Overview Given two binary search trees and a target sum, find all unique pairs of values (one from each tree) that add up to the target. This requires efficient traversal and searching techniques to handle large datasets within time constraints. Inefficient Approach (O(n²) complexity) The first approach involves traversing the first tre ...

Posted on Thu, 08 Oct 2026 16:01:16 +0000 by rustyofco

Dynamic Programming Approach to Knapsack Problems

Knapsack Problem Overview The knapsack problem involves selecting items with given weights and values to maximize total value within a weight cnostraint. 0/1 Knapsack Given n items and a knapsack with maximum capacity w, where each item has a weight weight[i] and value value[i], determine which items to include to maximzie value. Each item can ...

Posted on Wed, 07 Oct 2026 16:48:03 +0000 by Blondy

Backtracking Algorithm Fundamentals and LeetCode 77. Combinations

Backtracking Algorithm Fundamentals Backtracking is essentially an exhaustive search approach optimized to avoid writing nested loops of variable depths, which becomes impractical for large datasets. Key problem types backtracking solves: Combination problems: Find all valid k-element subsets from an n-element set Permutation problems: Determi ...

Posted on Tue, 06 Oct 2026 16:18:15 +0000 by undecided name 01

Algorithm Practice Day 11: Postfix Expression Evaluation, Sliding Window Maximum, and Top K Frequent Elements

Problem Solving 1.1 Evaluate Reverse Polish Notation Original Link: Code Suizhanglu Problem Link: 150. Evaluate Reverse Polish Notation - LeetCode Description Given an array of strings tokens represanting a postfix expression, compute the result of this expression. Return an integer representing the value of the expression. Notes: Valid oper ...

Posted on Sun, 04 Oct 2026 16:03:09 +0000 by jqa

Understanding Stack Data Structure: Sequential and Linked Implementations

Sequential Stack A sequential stack uses an array with a top pointer to track the top element. Stack Structure typedef struct { int items[MAXLEN]; int topIndex; } SeqStack; Initialize Stack void CreateSeqStack(SeqStack *stack) { stack->topIndex = -1; } Check If Empty int IsEmptySeq(SeqStack *stack) { return stack->topInd ...

Posted on Sat, 03 Oct 2026 16:50:32 +0000 by pob123

Find Kth Node from End in Linked List

Problem Overview Given a singly linked list, the task is to return the value of the k-th node from the end of the list. For example, given a list with nodes 1 → 2 → 3 → 4 → 5 and k = 2, the function should return 4, which is the value of the second node from the end. #### Solution 1: Calculate Length and Traverse This method involves two main s ...

Posted on Sat, 03 Oct 2026 16:25:07 +0000 by bfinucan

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

Efficient Exponentiation Using Fast Power Algorithm

The fast power algorithm is designed to compute large exponentiations efficiently, reducing time complexity from O(b) to O(log b). This method is particularly useful when dealing with modular arithmetic, such as calculating a^b mod m. Core Principle The fundamental idea relies on binary representation of the exponent. For any integer b, we can ...

Posted on Fri, 02 Oct 2026 16:38:07 +0000 by modigy

Replacing Words with Their Shortest Root Prefix

Problem Description In English, there exists a concept called root which can be combined with other words to form longer words called successors. To example, the root "an" combined with "other" forms the word "another". Given a dictionary of roots and a sentence, replace all successor words in the sentence with the ...

Posted on Thu, 01 Oct 2026 16:10:25 +0000 by sgalatas