Programming Articles

Page 401 of 2544

Rearrange String k Distance Apart in C++

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

Bitonic Sort in C++

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

The bitonic sort is a parallel sorting algorithm that is created for best implementation and has optimum usage with hardware and parallel processor array.It is not the most effective one though as compared to the merge sort. But it is good for parallel implementation. This is due to the predefined comparison sequence which makes comparisons independent of data that are to be sorted.For bitonic sort to work effectively the number of elements should be in a specific type of quantity i.e. the order 2^n.One major part of the bitonic sort is the bitonic sequence which is a sequence whose elements ...

Read More

Java Program to find largest prime factor of a number

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 3K+ Views

Following is the Java code to find the largest prime factor of a number −Exampleimport java.io.*; import java.util.*; public class Demo{    static long maxPrimeFactors( long val){       long max_prime = -1;       while (val % 2 == 0) {          max_prime = 2;          val >>= 1;       }       for (int i = 3; i 2)       max_prime = val;       return max_prime;    }    public static void main(String[] args){       int val = 148592;   ...

Read More

Python - Check if all elements in a list are identical

Pradeep Elance
Pradeep Elance
Updated on 11-Mar-2026 986 Views

There may be occasions when a list will contain all the values which are same. In this article we will see various way to verify that.With allWe use the all function to find the result of comparison of each element of the list with the first element. If each comparison gives a result of equality then the result is given as all elements are equal else all elements are not equal.ExamplelistA = ['Sun', 'Sun', 'Mon'] resA = all(x == listA[0] for x in listA) if resA:    print("in ListA all elements are same") else:    print("In listA all ...

Read More

Perfect Rectangle in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 325 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 479 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 470 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

Python - Check if given words appear together in a list of sentence

Pradeep Elance
Pradeep Elance
Updated on 11-Mar-2026 1K+ Views

Say we have a list containing small sentences as its elements. We have another list which contains some of the words used in this sentences of the first list. We want to find out if two words from the second list are present together in some of the sentences of the first list or not.With append and for loopWe use the for loop with in condition to check for the presence of words in the lists of sentences. Then we use the len function to check if we have reached the end of the list.Examplelist_sen = ['Eggs on Sunday', 'Fruits ...

Read More

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 419 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 4001–4010 of 25,433 articles
« Prev 1 399 400 401 402 403 2544 Next »
Advertisements