Articles on Trending Technologies

Technical articles with clear explanations and examples

Program to find sum of minimum trees from the list of leaves in python

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

Suppose we have a list of numbers called nums. This list is representing the leaf nodes in inorder traversal of a tree. Here the internal nodes have have 2 children and their value is same as the product of the largest leaf value of its left subtree and the largest leaf value of its right subtree. We have to find the sum of the tree with the minimum sum of its valuesSo, if the input is like nums = [3, 5, 10], then the output will be 83.To solve this, we will follow these steps:res := sum of all elements ...

Read More

Program to maximize the minimum value after increasing K sublists in Python

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

Suppose we have a list of numbers called nums and two values, size and k. Now suppose there is an operation where we take a contiguous sublist of length size and increment every element by one. We can perform this operation k times, we have to find the largest minimum value possible in nums.So, if the input is like nums = [2, 5, 2, 2, 7], size = 3, k = 2, then the output will be 3, as we can increase [2, 5, 2] to get [3, 6, 3, 2, 7] and then increment [6, 3, 2] to get ...

Read More

Check If a String Can Break Another String in C++

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

Suppose we have two strings s1 and s2 whose size are same; we have to check whether some permutation of string s1 can break some permutation of string s2 or vice-versa. A string a can break string b if x[i] >= y[i] (in alphabetical order) for all i in range 0 to n-1.So, if the input is like s1 = abc and s2 = xya, then the output will be true. This is because "ayx" is a permutation of s2 that can break to string "abc" which is a permutation of s1="abc".To solve this, we will follow these steps −Define ...

Read More

Program to find most occurring number after k increments in python

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

Suppose we have a list of numbers called nums and another value k. Let us consider an operation where we increase some element by one. We can perform at most k times, we have to find the value of the most frequently occurring number we can obtain. If there are more than one solution, select the smallest possible number.So, if the input is like nums = [1, 0, 0, 0, 8, 8, 8, 8] k = 8, then the output will be 8, as we can increase 1, 7 times to get 8, and increase any 0 to 1, so, ...

Read More

Program to maximize the number of equivalent pairs after swapping in Python

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

Suppose we have a list of numbers A and list of numbers B of same length. We also have a 2D list of numbers C where each element is of the form [i, j] this indicates we can swap A[i] and A[j] as many times as we want. We have to find the maximum number of pairs where A[i] = B[i] after the swapping.So, if the input is like A = [5, 6, 7, 8], B = [6, 5, 8, 7], C = [[0, 1], [2, 3]], then the output will be 4, as we can swap A[0] with A[1] ...

Read More

Check If All 1's Are at Least Length K Places Away in C++

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

Suppose we have an array nums of 0s and 1s and an integer k, we have to check whether all 1's are at least k places away from each other, otherwise, return False.So, if the input is like nums = [1, 0, 0, 0, 1, 0, 0, 1], k = 2, then the output will be true, as each of the 1s are at least 2 places away from each other.To solve this, we will follow these steps −last := -1for initialize i := 0, when i < size of nums, update (increase i by 1), do −if nums[i] is ...

Read More

How to create an only interaction regression model in R?

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

Mostly, we start with creating models by including single independent variables effect on the dependent variable and then move on to interaction. But if we are sure that there exists some interaction among variables and we are looking for the interaction effect then only interaction regression model can be created. This can be done by using colon sign between variables to signify the interaction as shown in the below examples.Example1Consider the below data frame:> x1 x2 x3 y df1 df1Outputx1 x2 x3 y 1 1 3 10 8 2 0 3 9 11 3 1 1 6 5 4 1 ...

Read More

Program to find minimum number of movie theatres required to show all movies in python

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

Suppose we have a list of intervals for different movie showings (they can be overlapped), we have to find the minimum number of theatres required to be able to show all of the movies.So, if the input is like intervals = [[20, 65], [0, 40], [50, 140]], then the output will be 2, as [20, 65] and [0, 40] are overlapping. [20, 65] and [50, 140] are also overlapping but [0, 40] and [50, 140] are not. So we need 2 theaters.To solve this, we will follow these steps:t := a new listfor each interval [a, b] in intervals, doinsert ...

Read More

Program to find maximum sum of non-adjacent nodes of a tree in Python

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

Suppose we have a binary tree, we have to find the maximum sum of the values that can be obtained given no two values can be adjacent parent to child.So, if the input is likethen the output will be 17 as 10, 4, 3 are not adjacent to each other.To solve this, we will follow these steps −Define a function f() . This will take nodeif node is null, thenreturn (0, 0)(a, b) := f(left of node)(c, d) := f(right of node)return a pair (maximum of value of node + b + d and a + c, a + c)from ...

Read More

Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit in C++

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

Suppose we have an array of integers called nums and an integer limit, we have to find the size of the longest non-empty subarray such that the absolute difference between any two items of this subarray is less than or equal to the given limit.So, if the input is like nums = [8, 2, 4, 7], limit = 4, then the output will be 2, this is because −[8] so |8-8| = 0 4.[8, 2, 4] so |8-2| = 6 > 4.[8, 2, 4, 7] so |8-2| = 6 > 4.[2] so |2-2| = 0 k) {   ...

Read More
Showing 3271–3280 of 61,248 articles
« Prev 1 326 327 328 329 330 6125 Next »
Advertisements