Articles on Trending Technologies

Technical articles with clear explanations and examples

Minimum Cost Path with Left, Right, Bottom and Up moves allowed in C++

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

Suppose we have a 2D array. Where each cell of which consists number cost which represents a cost to visit through that cell, we have to find a path from top-left cell to bottom-right cell by which total cost consumed is minimum.So, if the input is like32101661319111448158710111141751234891254221141100331124221then the output will be 340 as (32 + 11 + 14 + 48 + 66 + 13 + 19 + 7 + 34 + 12 + 21 + 42 + 21) = 340To solve this, we will follow these steps −Define cell with x, y coordinate and distance parameter.Define an array matrix of ...

Read More

Minimum Cost to cut a board into squares in C++

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

ConceptSuppose a board of length p and width q is given, we require to break this board into p*q squares such that cost of breaking is least. For this board, cutting cost for each edge will be given. In a nutshell, we require selecting such a sequence of cutting such that cost is minimized.Examples  With respect of above board optimal way to cut into square is −Total minimum cost in above case is 65. It is computed evaluated implementing following steps.Initial Value : Total_cost = 0 Total_cost = Total_cost + edge_cost * total_pieces Cost 5 Horizontal cut Cost = 0 + ...

Read More

Search a string in Matrix Using Split function in Java

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 198 Views

To search a string in Matrix using split function, the code is as follows −Exampleimport java.util.*; public class Demo {    public static int search_string(String[] my_matrix, String search_string){       for (String input : my_matrix){          String[] my_value = input.split(search_string);          if (my_value.length >= 2 || my_value.length == 0){             return 1;          }          else if (my_value.length == 1 && input.length() != my_value[0].length()){             return 1;          }       }   ...

Read More

Minimum Cuts can be made in the Chessboard such that it is not divided into 2 parts in C++

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

ConceptGiven A x B Chessboard, the task is to calculate the Maximum numbers of cuts that we can build in the Chessboard so that the Chessboard is not divided into 2 parts.Examples The examples are given below −Input A = 2, B = 4Output Number of maximum cuts = 3Input A = 2, B = 2Output Number of maximum cuts = 1MethodFor A = 2, B = 2 ,we can only build 1 cut (mark in red). If we build 1 more cut then the chessboard will divide into 2 piecesFor A = 2, B = 4 ,we can makes 3 cuts (marks in red). ...

Read More

Minimum edges required to add to make Euler Circuit in C++

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

ConceptWith respect of a given undirected graph of b nodes and a edges, the job is to determine minimum edges needed to build Euler Circuit in the given graph.Input b = 3, a = 2 Edges[] = {{1, 2}, {2, 3}}Output 1By connecting 1 to 3, we can build a Euler Circuit.MethodWith respect of a Euler Circuit to exist in the graph we need that every node should haveeven degree because then there exists an edge that can be applied to exit the node after entering it.Now, there can be two cases −Existence of one connected component in the graphWith respect of ...

Read More

Java Program for Largest K digit number divisible by X

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 256 Views

Following is the Java program for largest K digit number divisible by X −Exampleimport java.io.*; import java.lang.*; public class Demo{    public static int largest_k(int val_1, int val_2){       int i = 10;       int MAX = (int)Math.pow(i, val_2) - 1;       return (MAX - (MAX % val_1));    }    public static void main(String[] args){       int val_1 = 25;       int val_2 = 2;       System.out.println("The largest 2 digit number divisible by 25 is ");       System.out.println((int)largest_k(val_1, val_2));    } }OutputThe largest 2 digit ...

Read More

Java Program to Find sum of Series with n-th term as n^2 – (n-1)^2

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 369 Views

To find the sum of such series, the Java program is as follows −Examplepublic class Demo {    static long my_val = 1000000007;    public static long compute_val(long my_int){       return ((my_int % my_val) * (my_int % my_val)) % my_val;    }    public static void main(String[] args){       long my_int = 45687234;       System.out.println("The computed value is ");       System.out.print(compute_val(my_int));    } }OutputThe computed value is 335959495A class named Demo defines a function named ‘compute_val’ that computes and returns the sum of a specific series. In the main function, the long ...

Read More

Minimum removals from array to make GCD Greater in C++

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

ConceptWith respect of given N numbers, the target is to determine the minimum removal of numbers such that GCD of the remaining numbers is larger than initial GCD of N numbers. If it is impossible to increase the GCD, print “NO”.Input b[] = {1, 2, 4}Output1After removing the first element, then the new GCD is 2, which is larger than the initialGCD i.e., 1.Input b[] = {6, 9, 15, 30}Output 3The initial gcd is 3, after removing 6 and 9 to obtain a gcd of 15 which is larger than 3. We can also remove 9 and 15 to get a gcd of ...

Read More

Java Program for Stooge Sort

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 239 Views

Following is the Java program for Stooge sort −Exampleimport java.io.*; public class Demo {    static void stooge_sort(int my_arr[], int l_val, int h_val){       if (l_val >= h_val)       return;       if (my_arr[l_val] > my_arr[h_val]){          int temp = my_arr[l_val];          my_arr[l_val] = my_arr[h_val];          my_arr[h_val] = temp;       }       if (h_val-l_val+1 > 2){          int temp = (h_val-l_val+1) / 3;          stooge_sort(my_arr, l_val, h_val-temp);          stooge_sort(my_arr, l_val+temp, h_val);     ...

Read More

C program for pipe in Linux

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

Here, we will create a C program for pipe in Linux. In this program, we will read some text from the input stream and then print it to the output screen.First, let’s learn basics about pipe in LinuxPipe is used to transfer data, it can be used for communication between process/ command/ program for transferring standard output between two in Linux or Unix based system.One important thing to be noted is that pipes are unidirectional i.e. data can either flow from left to right or from right to left in the program.Here, we will create a pipe that will read ...

Read More
Showing 26891–26900 of 61,297 articles
Advertisements