Java Algorithm Patterns: Hash Maps to Array Manipulation
Hash Map Techniques
LeetCode 1: Two Sum
Utilize a hash map to store elements not yet encountered, while searching for the complement target - nums[i].
public int[] twoSum(int[] nums, int target) {
int[] result = new int[2];
Map<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < nums.length; i++) {
in ...
Posted on Fri, 08 May 2026 12:03:41 +0000 by SyWill
Four Classic NOIP 2010 Algorithm Problems with Solutions
Machine Translation Software (Queue Simulation)
Problem Description
A translation software maintains a memory buffer with M slots. When translating a word, the system first checks if the word exists in memory. If found, no external lookup is needed. Otherwise, it searches the dictionary, stores the word in memory, and increments the lookup coun ...
Posted on Fri, 08 May 2026 10:15:59 +0000 by neo926
Segment Tree with Lazy Propagation for Range Updates
Consider an array of (n) integers (a_1, a_2, \cdots, a_n). Two types of operations are supported:
Add a value (d) to all elements from index (l) to (r).
Query the maximum element within the range ([l, r]).
To efficiently handle these operations, we use a segment tree enhanced with lazy propagation. This technique introduces a lazy tag to defe ...
Posted on Fri, 08 May 2026 08:30:24 +0000 by Zaxnyd
Competitive Programming Weekly Solutions: Winter Algorithm Training Contests
2024 Nowcoder Winter Algorithm Training Camp 4
A - Lemon Soda
Check if the first value is at least k times the second value.
Complexity: O(1)
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int x, y, factor;
cin >> x >> y >> ...
Posted on Fri, 08 May 2026 03:23:40 +0000 by bigphpn00b
Linked List Problems: Swap Pairs, Remove Nth From End, Intersection, and Cycle Detection
24. Swap Nodes in Pairs
Problem: Swap adjacent nodes in a linked list pairwise, returnnig the new head. Do not modify node values—only rewire nodes.
Approaches:
Iterative: Use a dummy head to track the previous node. Adjust pointers for each pair.
Recursive: Swap the first two nodes, then recurce on the reamining list.
class Solution:
...
Posted on Fri, 08 May 2026 00:18:32 +0000 by dey.souvik007
Enhanced 2024 Parrot Optimization Algorithm with Multi-Strategy Improvements for Machine Learning Parameter Tuning
The multi-strategy enhanced parrot optimization algorithm (MEPO) integrates several optimization techniques and improvements to enhance global search capabilities and convergence speed. Below is an overview of each improvement strategy:
Population Initialization Using Cat Mapping + Reverse Strategy:
Cat Mapping Initialization: Utilizes the 'c ...
Posted on Fri, 08 May 2026 00:02:20 +0000 by ofSHIZ
Validate Binary Tree Nodes and Build Largest Multiple of Three
Validating Binary Tree Nodes
Given n nodes labeled from 0 to n-1, each with optional left (leftChild) and right (rightChild) children (denoted by -1 if absent), check if all nodes form exactly one valid binary tree.
Solution Code
const isValidBinaryTree = function(nodeCount, leftChildren, rightChildren) {
// Track parent of each node (-1 in ...
Posted on Thu, 07 May 2026 22:50:32 +0000 by happyness
Finding the Intersection Node of Two Linked Lists
Given the head nodes headA and headB of two singly linked lists, determine the node at which the two lists intersect. Return the intersecting node. If no intersection exists, return null.
The linked list structure is guraanteed to be acyclic. The original structure of both lists must remain unchanged after the function returns.
Example 1:
Input ...
Posted on Thu, 07 May 2026 16:21:41 +0000 by eMonk
Dynamic Programming Techniques for 0-1 and Unbounded Knapsack Problems
Core Implementation Strategy
Resolving knapsack variations follows a structured pattern involving state definition, initialization, and recurrence relation formulation. The primary distinction lies in whether an item can be selected multiple times or only once.
Phase 1: 0-1 Knapsack Variant
In this scenario, each item is available exact once pe ...
Posted on Thu, 07 May 2026 11:23:34 +0000 by pradee
Finding the Longest Palindromic Substring in Linear Time Using Manacher's Algorithm
Problem Statement
Given a string of length (n), find the length of the longest palindromic substring where (n \le 10^5).
Brute-Force Approach
A straightforward method involves iterating through each position as a potential center and expanding outward in both directions to check for palindromes. Taking the maximum length among all centers yield ...
Posted on Thu, 07 May 2026 03:39:19 +0000 by mdomel