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

Java Solutions for Blue Bridge Cup Algorithm Challenges

Secret Code Decoding Recover Chinese character bitmaps from byte sequences and interpret hidden messages. Each character is represented by 32 bytes arranged in 16 rows of 2 bytes. Convert byte values to binary, replacing 0s with spaces to visualize the characters. Constraints Max runtime: 1 second Max memory: 128MB <java> public class B ...

Posted on Fri, 15 May 2026 16:06:03 +0000 by Syphon

Computing Sorted Squares of a Non-Decreasing Integer Array

Method 1: Square then Sort This approach squares each element first and subsequently sorts the resulting array. #include <stdio.h> #include <stdlib.h> int compareElements(const void* first, const void* second) { int elemA = *((int*)first); int elemB = *((int*)second); if (elemA < elemB) return -1; if (elemA > elemB) r ...

Posted on Fri, 15 May 2026 09:48:25 +0000 by prc

Locating Target Boundaries in a Sorted Array via Binary Search

Problem StatementGiven an array of integers sorted in non-decreasing order, identify the starting and ending index of a specified target value. If the target is absent from the array, return [-1, -1]. The solution must operate with a logarithmic time complexity of O(log n).Expected OutcomesFor data = [5, 7, 7, 8, 8, 10], target = 8, the output ...

Posted on Fri, 15 May 2026 09:02:31 +0000 by heavenly

Implementing and Utilizing Stack Data Structures in Java

A stack is a linear collection that restricts element access to a single endpoint, commonly referred to as the top. This constraint enforces a Last-In-First-Out (LIFO) ordering, meaning the most recently added item is always the first to be removed. The two fundamental operations are push (insertion at the top) and pop (removal from the top). A ...

Posted on Fri, 15 May 2026 01:03:14 +0000 by mrprozac

Underlying Mechanisms of Python Set Deduplication

Python sets utilize a hash table implementation to store unique elements. The deduplication mechanism operates through a two-step verification process involving the __hash__ and __eq__ methods of the stored objects. Initially, the set evaluates the hash value of the incoming object. If this hash does not exist in the current hash table, the obj ...

Posted on Thu, 14 May 2026 23:00:25 +0000 by Love_Daddy

Java Algorithm Practice: Squares of Sorted Arrays, Minimum Size Subarray Sum, and Spiral Matrix II

977. Squares of a Sorted Array Problem Link on LeetCode Approach: Two Pointers Technique Since the array may contain negative numbers, we use two pointers to compare the squares of the elements from both ends. The left pointer starts at the beginning of the array, and the right pointer starts at the end. The larger square is placed at the curre ...

Posted on Thu, 14 May 2026 22:08:44 +0000 by cmanhatton

Algorithmic Approaches and Implementations for The 49th ICPC Asia Regionals Online Contest II

F-Tourist Iterate through the input array while tracking the cumulative score. Once the threshold of 4000 is reached, output the current one-based index and terminate early. #include <iostream> #include <vector> using namespace std; void solve() { int n; cin >> n; vector<int> scores(n); int target_thres ...

Posted on Thu, 14 May 2026 18:57:27 +0000 by jakobdoppler

Implementing Saddle Point Search and String Operations in C

Finding Saddle Points in a 2D Array A saddle point in an m×n matrix is an element that is both the maximum in its row and the minimum in its column. #include <stdio.h> void locateSaddlePoint(int matrix[100][100], int rows, int cols) { for (int row = 0; row < rows; row++) { int rowMax = matrix[row][0]; int maxCol = ...

Posted on Thu, 14 May 2026 11:36:24 +0000 by HairyArse

Common Linked List Algorithm Problems and Solutions

Node Class Definition The following ListNode class serves as the foundation for all examples in this article: import java.util.Arrays; public class ListNode { int data; ListNode next = null; public ListNode(int data) { this.data = data; } public String toString(ListNode node) { int[] values = new int[calcu ...

Posted on Thu, 14 May 2026 11:08:20 +0000 by duclet