AtCoder Beginner Contest 352 Solutions
Problem A - AtCoder Line Straightforward check: determine whether point z lies between x and y on the number line. Simply swap if necessary to ansure x ≤ y, then verify the condition. Click to view code
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int n, p, q, r;
scanf("%d%d%d%d", & ...
Posted on Thu, 16 Jul 2026 17:03:34 +0000 by craigbabe
Linked List Operations and Implementation Patterns in C
This document covers fundamental linked list operations including element removal, list reversal, node swapping, and intersection detection.
Removing Elements with Specific Value
Approach Without Dummy Node
This implementation handles edge cases by checking the head node separately before processing the rest of the list.
struct ListNode* remov ...
Posted on Thu, 16 Jul 2026 16:41:13 +0000 by foobar
Efficient Array Processing: Binary Search and Two-Pointer Techniques
Working with arrays is a cornerstone of algorithm development. This article delves into several effective strategies for managing and manipulating array data, including binary search for rapid element lookup and various two-pointer methodologies for in-place modifications and optimized transformations.
Binary Search
Binary search is an essen ...
Posted on Thu, 16 Jul 2026 16:23:40 +0000 by jumphopper
Solutions to a Set of Algorithmic Challenges from an ACGO Ranking Contest
Six problems drawn from a competitive programming rating competition are analysed below. Every solution is accompanied by both C++ and Python implementations. Keep in mind that Python code may run slower and care should be taken with complexity constants.
Problem 1 – Output a Digit Different from the Product
Given two integers a and b, print an ...
Posted on Thu, 16 Jul 2026 16:13:10 +0000 by machiavelli1079
Identifying a Valid Row Subset in a Binary Matrix via Bitmasking
In a binary matrix of size m x n, a subset of rows is considered "good" if, for every column, the sum of the elements in that column does not exceed half the size of the subset. Formally, if the subset conntains k rows, the sum of each column must be less than or equal to floor(k / 2). The goal is to return the indices of such a subse ...
Posted on Thu, 16 Jul 2026 16:05:53 +0000 by jsinker
Memoization Recursion and Dynamic Programming: Solving Optimization Problems Efficiently
Guess Number Higher or Lower II
We need to solve a game where we guess a number between 1 and n. Each wrong guess costs the amount equal to the guessed number. The goal is to find the minimum amount of money needed to guarantee a win regardless of which number is selected.
Brute-Force Recursion
class Solution {
public:
int calculateMinCost( ...
Posted on Wed, 15 Jul 2026 17:20:52 +0000 by djBuilder
AtCoder Beginner Contest 014 - Problem Solutions
Problem A
Given a snacks to distribute equally among b people. Snacks cannot be divided. Find the minimum number of additional snacks that need to be purchased.
Solution
Each person requires ceil(a/b) snacks. Therefore, the total snacks needed is ceil(a/b) * b. The additional snacks required is ceil(a/b) * b - a.
int snacks, people;
std::cin &g ...
Posted on Tue, 14 Jul 2026 17:33:54 +0000 by ypkumar
Three Implementations of Bubble Sort in Java
The basic bubble sort repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order. This process continues until the array is sorted.
import java.util.Arrays;
public class BubbleSort {
public static void main(String[] args) {
int[] data = {5, 8, 6, 3, 9, 2, 1, 7};
basicSort(da ...
Posted on Tue, 14 Jul 2026 17:32:18 +0000 by barnbuster
Mastering Backtracking: Generating Increasing Subsequences and Permutations
This article delves into advanced backtracking techniques for solving common algorithmic problems, specifically focusing on generating increasing subsequences and permutations, including handling duplicates.
Generating Increasing Subsequences (Problem 491)
Given an integer array, the task is to find all increasing subsequences with a length of ...
Posted on Tue, 14 Jul 2026 17:10:59 +0000 by Dominator69
Efficient Counter Implementation with Bit Arrays and Amortized Analysis
To implement a counter supporting both increment and reset operations in O(n) amortized time, we utilize a bit array along with a pointer tracking the position of the most significant set bit.
The data structure maintains:
A binary array bits representing the counter value
An index top_bit pointing to the highest-order 1-bit
For the increment ...
Posted on Tue, 14 Jul 2026 16:43:09 +0000 by stangoe