Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 118 of 377

Find Smallest Letter Greater Than Target in Python

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

Suppose we have a list of sorted characters’ letters. This is containing only lowercase letters, now we have a target letter t, we have to find the smallest element in the list that is larger than the given target.And letters also wrap around. So, if the target is t = 'z' and letters = ['a', 'b'], the answer is 'a'.So, if the input is like ["c", "f", "j"], t = 'a', then the output will be 'c'.To solve this, we will follow these steps −l := 0r := size of letters - 1while l target, thenr := mid -1otherwise, ...

Read More

Longest Substring with At Most K Distinct Characters in C++

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

Suppose we have a string; we have to calculate the length of the longest substring T that contains at most k distinct characters.So, if the input is like s = "eceba", k = 2, then the output will be 3 as T is "ece" which its length is 3.To solve this, we will follow these steps −ans := 0Define one map mn := size of sx := 0for initialize j := 0, i := 0, when j < n, update (increase j by 1), do −(increase m[s[j]] by 1)if m[s[j]] is same as 1, then −(increase x by 1)while (x > k and i k && i

Read More

Find median of BST in O(n) time and O(1) space in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 947 Views

ConceptWith respect of a given Binary Search Tree(BST), our task is to determine median of it.For even no. of nodes, median = ((n/2th node + (n+1)/2th node) /2 For odd no. of nodes, median = (n+1)/2th node.For given BST(with odd no. of nodes) is −       7       / \      4   9    / \   / \   2  5  8  10Inorder of Given BST will be : 2, 4, 5, 7, 8, 9, 10 So, here median will 7.For given BST(with even no. of nodes) is −         7   ...

Read More

Min Cost Climbing Stairs in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 929 Views

Suppose there is a staircase, here the i-th step will be some non-negative cost value cost[i] assigned. When we pay the cost, we can either climb one or two steps. We have to find minimum cost to reach the top of the floor, and we also can either start from the step with index 0, or the step with index 1.So, if the input is like cost = [12, 17, 20], then the output will be 17, The cheapest position to start from step 1 as we have to pay that cost and go to the top.To solve this, we ...

Read More

Rearrange String k Distance Apart in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 643 Views

Suppose we have a non-empty string s and an integer k; we have to rearrange the string such that the same characters are at least distance k from each other. Given strings are in lowercase letters. If there is no way to rearrange the strings, then we will an empty string.So, if the input is like s = "aabbcc", k = 3, then the output will be "abcabc" this is because same letters are at least distance 3 from each other.To solve this, we will follow these steps −ret := an empty stringDefine one map mn := size of sfor ...

Read More

Find memory conflicts among multiple threads in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 248 Views

Suppose we have a RAM and that RAM is organized in blocks. there are multiple processes running on the system. We have to keep in mind that every process gets following information, (Thread T, Memory Block M, time t, R/W) This indicates the thread T was implementing memory block M at given time t and operation could be either read(R) or write(W).The following case is indicating whether it is memory conflict or not −More than one read operations at the same location are not the reason of conflict.When writing operation is being performed between x+5 to x-5 to location of ...

Read More

Perfect Rectangle in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 327 Views

Suppose we have N axis-aligned rectangles, we have to check whether they all together form an exact cover of a rectangular region or not. Here each rectangle is represented as a bottom-left point and a top-right point. So a unit square is represented as [1, 1, 2, 2]. (bottom-left point is (1, 1) and top-right point is (2, 2)).So, if the input is like rectangles = [[1, 1, 3, 3], [3, 1, 4, 2], [3, 2, 4, 4], [1, 3, 2, 4], [2, 3, 3, 4]], then the output will be true as all 5 rectangles together form an exact ...

Read More

Find minimum adjustment cost of an array in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 483 Views

ConceptWith respect of a given array of positive integers, we replace each element in the array so that the difference between adjacent elements in the array is either less than or equal to a given target. Now, our task to minimize the adjustment cost, that is the sum of differences between new and old values. So, we basically need to minimize Σ|A[i] – Anew[i]| where 0 ≤ i ≤ n-1, n is denoted as size of A[] and Anew[] is denoted as the array with adjacent difference less than or equal to target. Let all elements of the array is ...

Read More

Largest Number At Least Twice of Others in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 473 Views

Suppose we have an integer array called nums, now there is always exactly one largest element. We have to check whether the largest element in the array is at least twice as much as every other number in the array. If it is so, then we have to find the index of the largest element, otherwise return -1.So, if the input is like [3, 6, 1, 0], then the output will be 1, as 6 is the largest number, and for every other number in the array x, 6 is more than twice as big as x. As the index ...

Read More

Find minimum s-t cut in a flow network in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 422 Views

Suppose we have following flow network. As we know an s-t cut is a cut that requires the source s node and a sink t node to be in different subsets, and it includes edges going from the source set to the sink side. Here the capacity of an s-t cut is represented by the sum of each edge capacity in the cut-set. Here we have to find minimum capacity s-t cut of the given network. Here the expected output is all edges of the minimum cut.So, if the input is likethen the output will be [(1, 3), (4, 3), ...

Read More
Showing 1171–1180 of 3,768 articles
« Prev 1 116 117 118 119 120 377 Next »
Advertisements