Articles on Trending Technologies

Technical articles with clear explanations and examples

Program to find latest group of size M using Python

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

Suppose we have an array arr holding a permutation of numbers from 1 to n. We have a binary string of size n with all bits initially set to zero. At each step i (1-indexed), we set the bit at position arr[i] to 1. Given a value m, we need to find the latest step at which there exists a group of ones of size exactly m. A group of ones means a contiguous substring of 1s that cannot be extended in either direction. If no such group exists, we return -1. Example Walkthrough If the input ...

Read More

Program to find minimum numbers of function calls to make target array using Python

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

Suppose we have a function that can perform two operations on an array: def modify(arr, op, index): if op == 0: arr[index] += 1 if op == 1: for i in range(len(arr)): arr[i] *= 2 We need to find the minimum number of function calls required to transform a zero array into a given target array nums. Problem Understanding ...

Read More

Program to find minimum number of vertices to reach all nodes using Python

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

Suppose we have a directed acyclic graph with n vertices numbered from 0 to n-1. The graph is represented by an edge list, where edges[i] = (u, v) represents a directed edge from node u to node v. We need to find the smallest set of vertices from which all nodes in the graph are reachable. The key insight is that nodes with no incoming edges cannot be reached from any other nodes, so they must be included in our starting set. Example Graph 0 ...

Read More

Program to find minimum operations to make array equal using Python

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

Suppose we have a value n, consider an array nums with n elements, where arr[i] = (2*i)+1 for all i. Now in one operation, we can choose two indices x and y where 0 = 0, add (n-j) to ans, decrement q, and increment j by 2 Return ans Example def solve(n): ans = 0 if n == 1: return ans q = (n // 2) - 1 j = 1 ...

Read More

Program to find maximum number of non-overlapping subarrays with sum equals target using Python

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

Given an array of numbers and a target value, we need to find the maximum number of non-overlapping subarrays where each subarray's sum equals the target. For example, if nums = [3, 2, 4, 5, 2, 1, 5] and target = 6, we can find two subarrays: [2, 4] and [1, 5], both with sum 6. Approach Using Prefix Sum and Set The key insight is to use prefix sums and track cumulative sums in a set. When we find a valid subarray, we reset our tracking to avoid overlaps. Algorithm Steps Initialize a ...

Read More

Program to find Kth bit in n-th binary string using Python

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

Suppose we have two positive values n and k. We can construct a binary string S_n using the following rules: S_1 = "0" S_i = S_(i-1) concatenate "1" concatenate reverse(invert(S_(i-1))) for i > 1 Here reverse(x) returns the reversed string x, and invert(x) flips all the bits in x (0 becomes 1, 1 becomes 0). Binary String Generation Pattern Let's see how these strings are constructed: S_1 = "0" S_2 = "011" S_3 = "0111001" ...

Read More

Program to check whether we can convert string in K moves or not using Python

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

In this problem, we need to determine if we can convert string s to string t using at most k moves. In the i-th move, we can select an unused index and shift the character at that position i times forward in the alphabet (with wrapping from 'z' to 'a'). Problem Understanding The key insight is that in move i, we can shift a character by exactly i positions. Since the alphabet wraps around, we need to calculate how many times each required shift distance can be achieved within k moves. Algorithm Steps Check if ...

Read More

Program to find minimum swaps to arrange a binary grid using Python

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

When working with binary matrices, we sometimes need to arrange rows so that all elements above the major diagonal are 0. This can be achieved by swapping adjacent rows. Let's explore how to find the minimum number of swaps required. Problem Understanding Given an n x n binary matrix, we need to swap adjacent rows to ensure all elements above the major diagonal are 0. If no solution exists, we return -1. For example, with this matrix: 010 011 100 We need to rearrange it so that elements above the diagonal are all ...

Read More

Program to find number of good leaf nodes pairs using Python

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

A binary tree contains good leaf node pairs when the shortest path between two different leaf nodes is less than or equal to a given distance d. Consider this binary tree with distance d = 4 ? 1 2 3 4 5 6 8 ...

Read More

Program to make a bulb switcher using binary string using Python

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

Suppose we have n bulbs in a room, numbered from 0 to n-1 and arranged in a row from left to right. Initially, all bulbs are turned off (0-state). We need to achieve a target configuration represented by a binary string where '1' means the bulb is on and '0' means it's off. The bulb switcher has a special flipping operation: Select any bulb index i Flip each bulb from index i to index n-1 (flip all bulbs from position i to the end) We need to find the minimum number of flips required to ...

Read More
Showing 1–10 of 61,303 articles
« Prev 1 2 3 4 5 6131 Next »
Advertisements