3 posts about Array Problems by 1 contributor.
Know Array Problems? Share what you know with developers who are learning it.
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.
Given an integer array, you can replace any number of elements with 1. The goal is to maximize the sum of absolute differences between consecutive elements. This article explains how to solve the problem efficiently using a two-state Dynamic Programming approach in O(n) time and O(1) auxiliary space. It includes the intuition, DP states, transitions, Java implementation, and a step-by-step dry run.
Master the Maximum Subarray Sum problem with at most one deletion using dynamic programming. Optimize with O(N) time and O(1) space.
DevSocialUpcoming · 3rd editionAI Agents ConferenceNov 23–27, 2026Live onlineMembers only16days leftRegisterPublish an article in this category and earn +1,000 SHARP when it is approved.
Write an article