Programming Articles

Page 191 of 2544

Check if a triplet with given sum exists in BST in Python

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

Suppose, we are provided with a Binary Search Tree (BST) that contains integer values, and a number 'total'. We have to find out if there are any group of three elements in the provided BST where the addition of the three elements is equal to the supplied 'total' value.So, if the input is liketotal = 12, then the output will be True.To solve this, we will follow these steps −temp_list := a new list initialized with zeroinorder traverse the tree and put it in temp_listfor i in range 0 to (size of temp_list - 2), increase by 1, doleft := ...

Read More

Program to evaluate s-expression as string in Python

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

Suppose we have a string s as S-expression. We have to evaluate that S-expression and return result as integer. As we know that the s-expression is an expression which is either one number, or a recursive expression wrapped in parentheses like (+ (- 3 2) (* 3 3)), which indicates (3 - 2) + (3 * 3) = 10. Here valid operators are +, -, *, and /.So, if the input is like s = "(- (+ 3 2) 2)", then the output will be 3, as ((3 + 2) - 2) = 3.To solve this, we will follow these ...

Read More

How to plot the confidence interval of the regression model using ggplot2 with transparency in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 855 Views

To plot the confidence interval of the regression model, we can use geom_ribbon function of ggplot2 package but by default it will have dark grey color. It can become transparent with the help of alpha argument inside the same function, the alpha argument can be adjusted as per our requirement but the most recommended value by me is 0.2.ExampleConsider the below data frame −> x y df dfOutput x y 1 22.67102 29.37057 2 21.59415 29.54027 3 20.56817 28.27672 4 24.97228 31.38193 5 21.41651 31.86811 6 23.94699 ...

Read More

Check if a word exists in a grid or not in Python

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

Suppose, we have a grid or a matrix of words. We have to check whether a given word is present in the grid or not. The word can be found in four ways, horizontally left and right and vertically up and down. If we can find the word we return True, otherwise False.So, if the input is likepghsfykdghtkghihnsjsojfghnrtyuinput_str = "python", then the output will be True.To solve this, we will follow these steps −Define a function find_grid() . This will take matrix, input_str, row_pos, col_pos, row_count, col_count, degreeif degree is same as size of input_str , thenreturn Trueif row_pos < ...

Read More

Element equal to the sum of all the remaining elements in C++

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

In this problem, we are given an array arr[] consisting of n positive values. Our task is to find the element equal to the sum of all the remaining elements of the array.Code Description: We need to find the element whose value is equal to the sum of all elements of the array except that element.Let’s take an example to understand the problem, Input: arr[] = { 5, 4, 17, 1, 7 }Output: 17Explanation −The sum of the rest of the element is (5 + 4 + 1 + 7 ) = 17, which is equal to the remaining element 17.Solution Approach −A simple ...

Read More

How to create a line for equal values of x and y in scatterplot in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 267 Views

To create a line for equal values of x and y in scatterplot, we can make use of segments function in base R but this can be done after creating the plot with the help of plot function. The segments function has four arguments, x0, y0, x1, and y1, we need to put the same value in x0 and y0 and the same value in x1 and y1 to draw the appropriate line as shown in the below examples.Example1> x xOutput[1] -1.14191974 1.11554154 -0.01255755 1.18841175 1.11300329 -0.69925814 [7] -0.88000117 0.67830803 -0.91237446 -1.14223973Example> y yOutput[1] -1.69229826 -0.70352587 0.38544874 0.14022473 0.15490539 -0.25938630 ...

Read More

Elements greater than the previous and next element in an Array in C++

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

In this problem, we are given an array arr[] of n positive integers. Our task is to create a program to find the elements greater than the previous and next element in an Array. Code Description: We need to find the elements of the array that satisfy the condition, the element is greater that the element at index 1 less than it and also is greater than the element at index 1 greater than it.Let’s take an example to understand the problem, Input: arr[] = {3, 2, 5, 7, 3, 4, 5}Output: 7Explanation −Element with index one less than the current element, 5.Element with ...

Read More

Program to find distance of shortest bridge between islands in Python

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

Suppose we have a binary matrix, where 0 represents water and 1 represents the land. An island is a group of connecting 1s in 4 directions. Islands are either surrounded by 0s (water) or by the edges. We have to find the length of shortest bridge that connects two islands.So, if the input is like001101100then the output will be 1. This will connect (1, 0) to (1, 2) points.To solve this, we will follow these steps −row := row count of matrixcol := column count of matrixDefine a function dfs() . This will take i, j, sif (i, j) is ...

Read More

How to visualize a data frame that contains missing values in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 407 Views

If a data frame contains missing value then visualising it in base R is not easily possible but we can make use of visdat package for this purpose. The vis_dat function of visdat package helps to visualize any data frame even if it contains missing values. For example, if a data frame df contains missing value then it can be visualized as vis_dat(df).Example1Consider the below data frame −> x1 x2 x3 df1 df1Output x1 x2 x3 1 1 23 10 2 1 23 NA 3 NA NA 10 4 NA NA 10 5 1 24 NA 6 2 22 NA ...

Read More

Elements of an array that are not divisible by any element of another array in C++

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

In this problem, we are given two arrays arr1[] and arr2[]. Our task is to create a program to find the elements of an array that are not divisible by any element of another array. Problem Description: Here, we need to find all elements from arr1 that are not divisible by any elements of arr2.Let’s take an example to understand the problem, Input: arr1[] = {17, 15, 5, 12, 8}        arr2[] = {5, 4}Output: 17Explanation −Elements of arr1 and elements dividing them, 17 -> no element can divide it.15 -> 5 divides the element.5 -> 5 divides the element.12 -> 4 ...

Read More
Showing 1901–1910 of 25,433 articles
« Prev 1 189 190 191 192 193 2544 Next »
Advertisements