Articles on Trending Technologies

Technical articles with clear explanations and examples

Program to find out the efficient way to study in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 202 Views

Suppose we have three lists of equal length representing course assignments: deadlines, credits, and durations. For the i-th assignment, deadlines[i] shows its deadline, credits[i] shows its credit value, and durations[i] shows the days needed to complete it. We must complete one assignment before starting another, and we can finish an assignment on its due date. We start at day 0. The goal is to find the maximum credits we can earn by efficiently scheduling assignments within their deadlines. Example Problem If we have deadlines = [7, 5, 10], credits = [8, 7, 10], and durations = [5, ...

Read More

Program to find maximum value by inserting operators in between numbers in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 503 Views

When given a list of numbers, we need to find the maximum value possible by inserting binary operators (+, -, *) and parentheses between them. This problem uses dynamic programming to explore all possible combinations of operations. For example, with nums = [-6, -4, -10], we can create the expression ((-6) + (-4)) * -10 = (-10) * (-10) = 100. Algorithm Steps The solution uses a recursive approach with memoization: For each subarray, calculate both minimum and maximum possible values Try all possible split points and operators Combine results from left and right subarrays ...

Read More

Program to find max values of sublists of size k in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 341 Views

Finding maximum values in sliding windows of size k is a common problem. We'll explore three approaches: brute force, optimized tracking, and using a deque for efficient sliding window maximum. Problem Understanding Given a list nums = [12, 7, 3, 9, 10, 9] and k = 3, we need to find the maximum value in each sublist of size 3: [12, 7, 3] → max = 12 [7, 3, 9] → max = 9 [3, 9, 10] → max = 10 [9, 10, 9] → max = 10 Method 1: Brute Force Approach ...

Read More

Program to find length of longest sublist whose sum is 0 in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 280 Views

Suppose we have a list with only two values 1 and −1. We have to find the length of the longest sublist whose sum is 0. So, if the input is like nums = [1, 1, −1, 1, 1, −1, 1, −1, 1, −1], then the output will be 8, as the longest sublist is [−1, 1, 1, −1, 1, −1, 1, −1] whose sum is 0. Algorithm To solve this, we will follow these steps − Create an empty hash map to store cumulative sum positions ...

Read More

Program to find length of longest substring which contains k distinct characters in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 888 Views

Finding the length of the longest substring with at most k distinct characters is a classic sliding window problem. We use two pointers to maintain a valid window and a hash map to track character frequencies. Problem Understanding Given a string s and number k, we need to find the maximum length of any substring that contains at most k distinct characters. For example, if k = 3 and s = "kolkata", the longest substrings with at most 3 distinct characters are "kolk" and "kata", both having length 4. Algorithm Steps We use the sliding ...

Read More

Program to find length of the longest path in a DAG without repeated nodes in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 1K+ Views

Finding the longest path in a Directed Acyclic Graph (DAG) without repeated nodes is a classic dynamic programming problem. Since the graph has no cycles, we can use memoization with depth-first search to efficiently compute the longest path from any starting node. Problem Understanding Given a DAG represented as an adjacency list, we need to find the length of the longest simple path (without repeated nodes). The example graph below shows nodes 0-4 with the longest path being 0 → 1 → 3 → 4 → 2 with length 4. ...

Read More

Program to find length of longest path with even sum in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 301 Views

When working with binary trees, we sometimes need to find the longest path where the sum of all node values is an even number. This problem requires tracking paths with even and odd sums separately using dynamic programming. Problem Understanding Given a binary tree, we need to find the length of the longest path whose sum is even. For example, in a tree with path [5, 2, 4, 8, 5], the sum is 24 (even) and the path length is 5. 2 5 ...

Read More

Program to find length of longest common subsequence of three strings in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 817 Views

The longest common subsequence (LCS) problem for three strings finds the maximum length of characters that appear in the same relative order across all three strings. This is an extension of the classic two-string LCS problem using dynamic programming. So, if the input is like s1 = "ababchemxde", s2 = "pyakcimde", s3 = "oauctime", then the output will be 4, as the longest common subsequence is "acme". Algorithm Steps To solve this, we will follow these steps − m := size of s1, n := size of s2, o := size of s3 dp := ...

Read More

Program to find length of longest arithmetic subsequence of a given list in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 567 Views

An arithmetic subsequence is a sequence where the difference between consecutive elements is constant. Given a list of numbers, we need to find the length of the longest arithmetic subsequence that can be formed. For example, if we have nums = [1, 4, 7, 10, 13, 20, 16], the longest arithmetic subsequence is [1, 4, 7, 10, 13, 16] with length 6, where each consecutive difference is 3. Algorithm Approach We use dynamic programming with a dictionary to store subsequence lengths. For each pair of elements, we calculate their difference and track the longest subsequence ending at ...

Read More

Program to check whether we can split list into consecutive increasing sublists or not in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 524 Views

Suppose we have a list of numbers called nums that is sorted in non-decreasing order. We need to check whether it can be split into subsequences where each subsequence has a minimum length of 3 and contains consecutively increasing numbers. So, if the input is like nums = [2, 3, 4, 4, 5, 6, 7], then the output will be True, as we can split the list into [2, 3, 4] and [4, 5, 6, 7]. Algorithm Approach To solve this problem, we will follow these steps − counts − A ...

Read More
Showing 5881–5890 of 61,299 articles
« Prev 1 587 588 589 590 591 6130 Next »
Advertisements