Competitive Programming Problem Solutions: A Holiday Practice Log
Mock Contest Problem 1
Problem Overview
Converting the constraints reveals two key requirements for any valid set:
Must include the maximum power of each prime factor of n
Must contain at least one pair of distinct prime factors
Since the number of prime factors is much smaller than log(n), brute force search works effectively.
Approach: Incl ...
Posted on Fri, 26 Jun 2026 17:15:55 +0000 by obay
Understanding and Implementing Splay Trees for Efficient BST Operations
Splay trees are self-adjusting binary search trees where each accessed node is rotated to the root through a sequence of tree rotations. Although the initial structure satisfies BST ordering, intermediate states may not, yet the in-order traversal remains consistent.
Rotation Mechanics
Rotations follow the same scheme as Treaps: zig (single rot ...
Posted on Fri, 05 Jun 2026 16:33:12 +0000 by Fox1337
Implementation of a Singly Linked List
#include <bits/stdc++.h>
using namespace std;
class Node {
public:
int value;
Node* next;
};
bool initialize(Node*& list) {
list = new Node;
if (!list) return false;
list->next = nullptr;
return true;
}
bool addAtHead(Node*& list, Node* element) {
if (!list || !element) return false;
element-& ...
Posted on Sun, 31 May 2026 22:21:19 +0000 by rashpal
Building a Minimal Blockchain from the Ground Up
Blockchain is a decentralized, tamper-resistant technology for recording data. It consists of a chain of data blocks, where each block contains transaction records and metadata. Every block connects to its predecessor through cryptographic hash functions, forming an ever-growing chain.
This article walks through blockchain fundamentals via impl ...
Posted on Sun, 24 May 2026 16:44:53 +0000 by chrisredding
Introduction to Segment Trees
What is a Segment Tree?
A segment tree is a binary tree-based advanced data structure that supports flexible range operations. Unlike a Fenwick Tree (Binary Indexed Tree) which is limited to simple point update/range query use cases, segment trees can handle range updates with point queries, and even full range updates with range queries effici ...
Posted on Wed, 20 May 2026 07:33:16 +0000 by Stryks
Understanding Algorithm Efficiency and Data Structures
Problem Statement
Consider the following problem: Find all possible combinations of a, b, and c such that a + b + c = 1000 and a^2 + b^2 = c^2 (where a, b, and c are natural numbers).
Initial Attempt
import time
start_time = time.time()
# Note: triple loop
for a in range(0, 1001):
for b in range(0, 1001):
for c in range(0, 1001):
...
Posted on Fri, 15 May 2026 15:21:00 +0000 by noblegas