Programming Articles

Page 1318 of 2547

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 442 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

Bitwise and (or &) of a range in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 271 Views

In this problem, we are given two integer values a and b. And our task is to find the bitwise and (&) of range from a to b. This means we will have to find the value of a & a+1 & a+2 & … b-1 & b.Let’s take an example to understand the problem, Input − a = 3 , b = 8Output − 0Explanation − 3 & 4 & 5 & 6 & 7 & 8 = 0To solve the problem, a simple solution is starting from a and find bitwise and of all numbers by increasing one ...

Read More

Minimum Unique Word Abbreviation in C++

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

Suppose we have a string such as "word" and that contains the following abbreviations: ["word", "1ord", "w1rd", "wo1d", "wor1", "2rd", "w2d", "wo2", "1o1d", "1or1", "w1r1", "1o2", "2r1", "3d", "w3", "4"]. We also have a target string and a set of strings in a dictionary, we have to find an abbreviation of this target string with the smallest possible length such that it does not conflict with abbreviations of the strings in the dictionary. Here each number or letter in the abbreviation is considered as length = 1. So as an example, the abbreviation "a32bc" is of length = 4.So, if ...

Read More

Find minimum time to finish all jobs with given constraints in C++

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

ConceptWith respect of a given array of jobs with different time requirements, there exists k identical assignees available and we are also provided how much time an assignee consumesto do one unit of the job. Our task is to determine the minimum time to complete all jobs with following constraints.The first constraint is that an assignee can be assigned only contiguous jobs.Here, for example, an assignee can be assigned jobs at position 1 and 2, but not at position 3, in an array.The second constraint is that two assignees cannot share (or co-assigned) a job, that means, a job cannot ...

Read More

Java Program to find the perimeter of a cylinder

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 324 Views

Following is the Java code to find the perimeter of a cylinder −Exampleimport java.io.*; public class Demo{    static int find_peri(int dia, int ht){       return 2*(dia + ht);    }    public static void main(String[] args){       int dia = 7;       int ht = 15;       System.out.println("The perimeter of the cylinder is " + find_peri(dia, ht) + " units");    } }OutputThe perimeter of the cylinder is 44 unitsA class named Demo defines a static function that takes in two values, diameter and height. This function computes the sum of ...

Read More

Bitwise AND of sub-array closest to K in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 1K+ Views

In this problem, we are given an array arr[] of size n and an integer k. Our task is to find the subarray within from index i to j and compute bitwise AND of all its elements. After this print minimum value of abs(K- (bitwise AND of subarray)).Let’s take an example to understand the problem, Input − arr[] = {5, 1}, k = 2Output −To solve the problem, there can be a few methods.One simple solution will be using the direct method. By finding bitwise AND for all sub-arrays then finding the |K-X|.Step 1 − Find the bitwise AND for ...

Read More

Maximum students to pass after giving bonus to everybody and not exceeding 100 marks in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 211 Views

In this tutorial, we will be discussing a program to find maximum students to pass after giving bonus to everybody and not exceeding 100 marks.For this we will be provided with an array containing marks of N students. Our task is to get more student pass the exam (50 marks required) by giving each student the same amount of bonus marks without any student exceeding 100 marks.Example#include #include using namespace std; int check(int n, int marks[]) {    int* x = std::max_element(marks, marks+5);    int bonus = 100-(int)(*x);    int c = 0;    for(int i=0;    i= 50) c ...

Read More

Find multiplication of sums of data of leaves at same levelss in C++

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

ConceptWith respect of a given Binary Tree, return following value for it.With respect of every level, calculate sum of all leaves if there are leaves at this level. Else ignore it.Calculate multiplication of all sums and return it.InputRoot of following tree       3      / \     8   6          \           10Output80First level doesn’t have leaves. Second levelhas one leaf 8 and third level also has one leaf 10. So result is 8*10 = 80InputRoot of following tree              3     ...

Read More

Maximum subarray size, such that all subarrays of that size have sum less than k in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 234 Views

In this tutorial, we will be discussing a program to find maximum subarray size, such that all subarrays of that size have sum less than k.For this we will be provided with an array of size N and an integer k. Our task is to find the length of subarray such that all the sub-arrays of that length in the given array sum to be less than or equal to k.Example#include using namespace std; //finding maximum length subarray int bsearch(int prefixsum[], int n, int k) {    int ans = -1;    //performing binary search    int left = 1, ...

Read More

Word Squares in C++

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

Suppose we have a set of words (all are unique), we have to find all word squares and we can build from them. Here a sequence of words forms a valid word square if the kth row and column read the exact same string, where 0 ≤ k < maximum of numRows and numColumns. So as an example, the word sequence ["ball", "area", "lead", "lady"] will construct a word square because each word reads the same both horizontally and vertically.ballarealeadladySo, if the input is like ["area", "lead", "wall", "lady", "ball"], then the output will be [[ "wall", "area", "lead", "lady"], ...

Read More
Showing 13171–13180 of 25,466 articles
Advertisements