Programming Articles

Page 230 of 2545

Program to get indices of a list after deleting elements in ascending order in Python

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

Suppose we have a list of distinct values and we want to remove each number in non-decreasing order. We have to find the indices of numbers in order of their deletion.So, if the input is like nums = [4, 6, 2, 5, 3, 1], then the output will be [5, 2, 3, 0, 1, 0] as we delete 1, so array is [4, 6, 2, 5, 3], then remove 2, array is [4, 6, 5, 3], then remove 3 we get [4, 6, 5], then remove 4 we get [6, 5], remove 5, [6] and finally remove 6.To solve this, we will follow these steps −Define a function my_sort() . This will take indsif size of inds

Read More

Check whether given string can be generated after concatenating given strings in Python

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

Suppose we have two strings s and t and r, we have to check whether r = s | t or r = t + s where | denotes concatenation.So, if the input is like s = "world" t = "hello" r = "helloworld", then the output will be True as "helloworld" (r) = "hello" (t) | "world" (s).To solve this, we will follow these steps −if size of r is not same as the sum of the lengths of s and t, thenreturn Falseif r starts with s, thenif r ends with t, thenreturn Trueif r starts with t, ...

Read More

How to find the maximum of each row in an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 7K+ Views

Sometimes we need maximum values, it helps us to identify which case or subject occurs at the greatest point hence we can understand the limit for the sample or population under study. If we want to find the maximum of values two or more columns for each row in an R data frame then pmax function can be used.ExampleConsider the below data frame −set.seed(1997) x1

Read More

Program to check whether odd length cycle is in a graph or not in Python

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

Suppose we have an undirected graph we have to check whether we can find an odd length cycle inside it or not.So, if the input is like adj_list = [[1, 2], [0, 3, 4], [0, 3, 4], [1, 2, 4], [1, 2, 3]]then the output will be True as there are odd length cycles like [0, 1, 3, 4, 2], [1, 3, 4], [2, 3, 4].To solve this, we will follow these steps −Define a function dfs() . This will take node, iif node is in path, thenreturn true when (i - path[node]) is oddif node is visited, thenreturn Falsemark ...

Read More

Check whether given three numbers are adjacent primes in Python

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

Suppose we have three numbers and we have to check whether they are adjacent primes are not. The adjacent primes are prime numbers where no other prime is present between them.So, if the input is like nums = [5, 7, 11], then the output will be True.To solve this, we will follow these steps −if any one of these three numbers is not prime themreturn Falseif next prime of x is not same as y, thenreturn Falseif next prime of y is not same as z, thenreturn Falsereturn TrueLet us see the following implementation to get better understanding −Example Codedef ...

Read More

Program to find sum of the right leaves of a binary tree in C++

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

Suppose we have a binary tree we have to find the sum of all right leaves in a given binary tree.So, if the input is likethen the output will be 17, as there are two right leaves in the binary tree, with values 7 and 10 respectively.To solve this, we will follow these steps −Define a function dfs(), this will take node, add, if node is null, then −returnif left of node is null and right of node is null and add is non-zero, then −ret := ret + val of nodedfs(left of node, false)dfs(right of node, true)From the main ...

Read More

Count the pairs of vowels in the given string in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 420 Views

We are given with a string of characters and the task is to calculate the count of pairs having both the elements as vowels. As we know there are five vowels in English alphabet i.e. a, i, e, o, u and other characters are known as Consonants.Input − string str = "tutorials point”Output − Count the pairs of vowels in the given string are: 2Explanation − From the given string we can form pairs as (t, u), (u, t), (t, o), (o, r), (r, i), (i, a), (a, l), (l, s), (s, p), (p, o), (o, i), (i, n) and ...

Read More

Program to find length of longest sublist where difference between min and max smaller than k in Python

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

Suppose we have a list of numbers called nums and another value k, we have to find the length of longest sublist where the absolute difference between the largest and smallest element is ≤ k.So, if the input is like nums = [2, 4, 6, 10] k = 4, then the output will be 3, as we can select pick [2, 4, 6] here the absolute difference is 4.To solve this, we will follow these steps −Create two double ended queue maxd, mindi := 0, res := 1for each index j and value a in A, dowhile maxd is not ...

Read More

Program to find sum of the deepest nodes in C++

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

Suppose we have a binary tree; we have to find the sum of values of its deepest leaves. So if the tree is like −Then the output will be 11.To solve this, we will follow these steps −Define a map m, and maxDepthDefine a recursive method solve(), this will take node and level, initially level is 0if node is not present, then returnmaxDepth := max of level and maxDepthincrease m[level] by value of nodesolve(left of node, level + 1)solve(right of node, level + 1)In the main method, setup maxDepth := 0, then solve(root, 0)return m[maxDepth]Let us see the following implementation ...

Read More

Program to find length of longest substring with character count of at least k in Python

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

Suppose we have a string s where each characters are sorted and we also have a number k, we have to find the length of the longest substring such that every character occurs at least k times.So, if the input is like s = "aabccddeeffghij" k = 2, then the output will be 8, as the longest substring here is "ccddeeff" here every character occurs at least 2 times.To solve this, we will follow these steps −Define a function rc() . This will take lstc := a map with all characters and their occurrencesacc := a new listans := 0valid ...

Read More
Showing 2291–2300 of 25,445 articles
« Prev 1 228 229 230 231 232 2545 Next »
Advertisements