Learn how to count array subsets whose MEX falls within a given range using frequencies, powers of two, and modular arithmetic in Java.
Learn how to minimize file-merge cost using a greedy min-heap strategy in Java with PriorityQueue, including examples, a dry run, and complexity analysis.
Learn how to find the nth character in the infinite concatenation of positive integers using digit ranges and arithmetic, without generating the full string.
Learn a dynamic-programming approach to maximize a binary string's weight by forming non-overlapping alternating pairs while accounting for toggle costs.
Learn how to determine whether a movement-command path can fit in a grid by tracking its relative bounding rectangle in O(|s|) time.
Solve a wildcard palindrome problem by minimizing the total ASCII difference between adjacent characters, including impossibility checks and a Java implementation.
Learn how to count array indices whose jump paths escape the array using Java DFS, state tracking, memoization, and cycle detection.
Learn how to calculate the minimum project completion time in Java using topological sorting, Kahn's algorithm, and dynamic programming to handle dependencies and detect cycles.
Learn how to count distinct paths from a grid coordinate to the origin using dynamic programming, base cases, and a recurrence relation in Java.
Learn how to solve Range GCD Queries using a Segment Tree in Java 21 with efficient range queries, point updates, and Euclidean Algorithm.
Learn how to solve the Minimum Cost Pizza Selection problem using Dynamic Programming. Given the area and cost of Small, Medium, and Large pizzas, the goal is to find the minimum cost required to achieve a total area of at least x. This article explains the DP approach, state definition, transition, handling of area greater than x, dry run, Java implementation, and complexity analysis.
Learn how to solve the Box Stacking Problem using Dynamic Programming in Java with box rotations, normalized bases, stacking rules, and O(n²) complexity.
Learn how to solve the maximum disc stack problem using dynamic programming and a Fenwick Tree for an efficient O(n log n) Java solution.
Learn how to solve the Pyramid Array with Reduce Operations problem using Dynamic Programming in Java. This article explains how to calculate the maximum possible pyramid height at every position using left and right DP arrays. It also covers the key observation that a pyramid with peak height x has a total sum of x², allowing us to calculate the minimum reduction cost efficiently in O(n) time and O(n) auxiliary space.
Learn how to solve the Longest Matching Word in Dictionary with Removals problem in Java. This article explains the subsequence concept, character position preprocessing, binary search, greedy matching, complete Java solution, dry run, and time and space complexity.
Learn how to check whether the nodes at every corresponding level of two binary trees are anagrams using Java. This article explains the Level Order Traversal (BFS) approach, how to use HashMap to compare node frequencies, step-by-step code implementation, dry run, and time and space complexity.
Find the minimum absolute difference between any two different nodes in a Binary Search Tree (BST) using inorder traversal. This article explains how the BST property helps generate sorted values and how comparing adjacent values gives an efficient O(n) solution in Java.
Learn how to solve the Minimum Edge Reversals for a Path problem using 0-1 BFS and a Deque. The article explains how to convert directed edges into weighted edges with costs 0 and 1, find the minimum number of reversals required to reach the destination, and implement the solution efficiently in Java with O(n + m) time complexity.
Given an even-sized integer array, divide the array into two equal halves. A pair (i, j) is considered a dominant pair if i belongs to the first half, j belongs to the second half, and arr[i] >= 5 × arr[j]. The goal is to count the total number of dominant pairs efficiently. A brute-force approach takes O(n²) time. By sorting both halves independently and using the two-pointer technique, we can solve the problem in O(n log n) time. This problem is a good example of how sorting can optimize pair-counting problems by avoiding unnecessary comparisons.
Learn how to maximize leaf nodes within a budget using BFS, level-based costs, frequency counting, and a greedy strategy in Java with O(n + k) time.
Find the maximum product that can be obtained by selecting exactly k elements from an integer array. The solution uses dynamic programming by maintaining both the maximum and minimum products for each subsequence size. Keeping both values is important because multiplying two negative numbers can produce a positive maximum product. The approach correctly handles positive numbers, negative numbers, zero, odd and even values of k, and all-negative arrays.
Learn how to count ordered pairs with a given GCD and LCM in Java using prime factorization, the GCD-LCM identity, and the 2^k counting technique.
Learn how to solve the Word in Grid problem in Java using eight-directional traversal, direction arrays, boundary checks, duplicate handling, and O(n × m × k) complexity.
Learn how to solve the Bird and Max Fruit Gathering problem efficiently using the Sliding Window technique. In this problem, trees are arranged in a circle, and the bird can visit at most m consecutive trees to collect the maximum possible fruits.
Learn how to find the number from 1 to n with the maximum digit sum using a digit-based optimization approach, efficient candidate generation, and Java.
DevSocialUpcoming · 3rd editionAI Agents ConferenceNov 23–27, 2026Live onlineMembers only17days leftRegisterMembers onlyWrite an article and earn +1,000 SHARP when it is approved.
Write an article