Compressing 2-D Grids with Sparse Matrices

int rows = 11; int cols = 11; int[][] grid = new int[rows][cols]; grid[1][2] = 1; grid[2][3] = 2; // display the original grid for (int[] row : grid) { for (int v : row) System.out.print(v + " "); System.out.println(); } // count non-zero entries int nonZero = 0; for (int i = 0; i < rows; i++) for (int j = 0; j < c ...

Posted on Thu, 20 Aug 2026 16:28:38 +0000 by ONiX

Solutions to Competitive Programming Problems

Problem A: Graph Coloring We are given an integer n and need to color the integers from 1 to n. The constraint is that for any two integers i and j where i < j, if their difference j - i is a prime number, they must have differant colors. The goal is to use the minimum number of colors possible and provide a valid coloring scheme. For n > ...

Posted on Wed, 19 Aug 2026 16:36:35 +0000 by cool30

CDQ Divide and Conquer and Chtholly Tree Explained

Part 1: CDQ Divide and Conquer CDQ divide and conquer is primarily used to solve 3D partial order problems, where we need to count valid pairs of elements satisfying three specified attribute constraints. For example, given elements with attributes (a_i, b_i, c_i), we might calculate how many j satisfy a_j ≤ a_i, b_j ≤ b_i, and c_j ≤ c_i for ea ...

Posted on Wed, 19 Aug 2026 16:26:21 +0000 by MtPHP2

Implementing Linked List Addition for Reverse-Order Digits in Java

Problem Overview When working with numerical data structures, a common algorithmic challenge involves adding two non-negative integers represented as singly linked lists. In this specific arrangement, each node stores a single digit, and the digits are stored in reverse order (least significant digit at the head). The objective is to compute th ...

Posted on Sun, 16 Aug 2026 16:57:59 +0000 by oskom

Codeforces Round 166 Div. 2: A Walkthrough

This document details the solutions for problems from Codeforces Educational Round 166 (Rated for Div. 2). A. Verify Password The problem requires validating a password string based on specific criteria. The approach involves iterating through the password and checking adjacent character pairs against the rules. A password is valid if it adhere ...

Posted on Sun, 16 Aug 2026 16:50:06 +0000 by mainewoods

Algorithmic Techniques for Common LeetCode Problems

Single Number Given a non-empty array of integers where every element appears twice except for one, find that single one using bitwise XOR. The XOR operation has two critical properties: commutativity (a ^ b == b ^ a) and identity (x ^ x == 0 and x ^ 0 == x). Consequently, XORing all numbers in the array cancels out the pairs, leaving the uniqu ...

Posted on Sat, 15 Aug 2026 16:45:20 +0000 by healthbasics

Backtracking Algorithm Practice: Combination Sum III and Letter Combinations

Problem 216: Combination Sum III Description: Given two integers k and n, find all possible combinations of k numbers from 1 to 9 that add up to n. Each number can only be used once in a combination. Approach This problem requires finding subsets of size k from the set [1,2,3,4,5,6,7,8,9] where the sum equals n. The parameter k represents the d ...

Posted on Sat, 15 Aug 2026 16:09:44 +0000 by heerajee

Hash Tables in Algorithmic Problem Solving: A Practical Guide

Valid Anagram A hash table can be used to efficiently determine if two strings are anagrams by counting character frequencies. By storing the frequency of each character from the first string and then decrementing the count for each character found in the second string, we can verify if all counts return to zero. class Solution { public: ...

Posted on Thu, 13 Aug 2026 16:01:30 +0000 by djjamiegee

Implementing a High-Performance SAT Solver with CDCL and 2-Literal Watching Mechanisms

Overview The Satisfiability Problem (SAT) is a fundamental decision problem in computer science, asking whether there exists an interpretation that satisfies a given Boolean formula. This implementation details a high-performance SAT solver based on the Davis-Putnam-Logemann-Loveland (DPLL) algorithm, enhanced with modern Conflict-Driven Clause ...

Posted on Wed, 12 Aug 2026 16:37:25 +0000 by planethax

Blue Bridge Cup 2019 Provincial A: Takeout Shop Priority

In the "Bao Le Me" food delivery system, there are N restaurents numbeerd from 1 to N. Each restaurant has a priority value that starts at 0 at time 0. For every time unit: If a restaurant receives no orders, its priority decreases by 1, but never goes below 0. If it receives one or more orders, its priority increases by 2 per order. ...

Posted on Wed, 12 Aug 2026 16:17:15 +0000 by calbolino