Found 26504 Articles for Server Side Programming

Program to find minimum number of cells it will take to reach bottom right corner in Python

Arnab Chakraborty
Updated on 21-Oct-2020 12:04:30

226 Views

Suppose we have a 2D grid representing a maze where 0 is for empty space, and 1 is the wall. We will start at grid[0, 0], we have to find the minimum number of squares it would take to get to bottom right corner of the grid. If we cannot reach, return −1.So, if the input is like000100100then the output will be 5To solve this, we will follow these steps −R := row count of grid, C := column count of gridq := [0, 0, 1] when A[0, 0] is 1 otherwise a new listA[0, 0] := 1for each (r, ... Read More

Program to find spreadsheet column number from the column title in C++

Arnab Chakraborty
Updated on 21-Oct-2020 12:02:35

144 Views

Suppose we have a column title of spreadsheet. We know that the spreadsheet column numbers are alphabetic. It starts from A, and after Z, it will AA, AB, to ZZ, then again AAA, AAB, to ZZZ and so on. So column 1 is A, column 27 is Z. Here we will see how to get the column letter if number of column is given. So if the column number is 80, then it will be CB. So we have to find the corresponding column title from the number. If the input is like 30, it will AD.Example Live Demo#include #include using ... Read More

Program to find spreadsheet column title from the column number in C++

Arnab Chakraborty
Updated on 21-Oct-2020 12:00:42

216 Views

Suppose we have a positive integer value; we have to find its corresponding column title as appear in a spread sheet. So [1 : A], [2 : B], [26 : Z], [27 : AA], [28 : AB] etc.So, if the input is like 29, then the output will be AC.To solve this, we will follow these steps −while n is non-zero, do −n := n − 1res := res + n mod 26 + ASCII of 'A'n := n / 26reverse the array resreturn resLet us see the following implementation to get better understanding −Example Live Demo#include using namespace std; ... Read More

Program to schedule tasks to take smallest amount of time in Python

Arnab Chakraborty
Updated on 21-Oct-2020 11:59:05

239 Views

Suppose we have a list of values called tasks where each different value represents a different task type, and we also have a non-negative integer k. Each task wants one minute to complete, but we must wait k minutes between doing two tasks of the same type. At any time, we can be doing a task or waiting. We have to find the smallest amount of time it takes to complete all the tasks.So, if the input is like nums = [2, 2, 2, 3, 3, 2], k = 1, then the output will be 7, as the optimal ordering ... Read More

Program to find number of given operations required to reach Target in Python

Arnab Chakraborty
Updated on 21-Oct-2020 11:57:08

397 Views

Suppose we have two values start and end, we have to find the minimum number of operations needed to convert start to end by using these operations −Decrement by 1Multiply by 2So, if the input is like start = 2, end = 7, then the output will be 3, as we can multiply 2 to get 4, then multiply 2 to get 8 and then subtract 1 to get 7.To solve this, we will follow these steps −ans := 0Do the following infinitely, doif end

Program to check whether given tree is symmetric tree or not in Python

Arnab Chakraborty
Updated on 21-Oct-2020 11:54:58

291 Views

Suppose we have one binary tree. We have to check whether the tree is symmetric tree or not. A tree will be said to be symmetric if it is same when we take the mirror image of it. From these two trees, the first one is symmetric, but second one is not.To solve this, we will follow these steps.We will call following steps recursively. The function will be solve(root, root)if the node1 and node2 are empty, then return trueif either node1 or node2 is empty, then return falsereturn true when node1.val = node2.val and solve(node1.left, node2.right) and solve(node1.right, node2.left)Let us ... Read More

Program to check whether two trees can be formed by swapping nodes or not in Python

Arnab Chakraborty
Updated on 21-Oct-2020 11:50:02

173 Views

Suppose we have two trees, we have to check whether we can transform first tree into second one by swapping any node's left and right subtrees any number of times.So, if the input is likethen the output will be TrueTo solve this, we will follow these steps −que1 := a queue with root0 initiallyque2 := a queue with root1 initiallywhile que1 and que2 are not empty, dotemp1 := a new list, temp2 := a new listvalues1 := a new list, values2 := a new listif que1 and que2 are containing different number of elements, thenreturn Falsefor i in range 0 ... Read More

Program to check whether each node value except leaves is sum of its children value or not in Python

Arnab Chakraborty
Updated on 21-Oct-2020 11:46:21

345 Views

Suppose we have a binary tree, we have to check whether for every node in the tree except leaves, its value is same as the sum of its left child's value and its right child's value or not.So, if the input is likethen the output will be TrueTo solve this, we will follow these steps −Define a function dfs() . This will take rootif root is null, thenreturn Trueif left of root is null and right of root is null, thenreturn Trueleft := 0if left of root is not null, thenleft := value of left of rootright := 0if right ... Read More

Program to find three unique elements from list whose sum is closest to k Python

Arnab Chakraborty
Updated on 21-Oct-2020 11:43:13

239 Views

Suppose we have a list of numbers called nums and another value k, we have to find three unique entries in nums (a, b, c) such that |a + b + c − k| is minimized and return the absolute difference.So, if the input is like nums = [2, 5, 25, 6] k = 14, then the output will be 1 as if we take [2, 5, 6] will get us closest to 14 and the absolute difference is |13 − 14| = 1.To solve this, we will follow these steps −sort the list numsans := 1^9for i in range ... Read More

Program to check number of triplets from an array whose sum is less than target or not Python

Arnab Chakraborty
Updated on 21-Oct-2020 11:40:48

193 Views

Suppose we have a list of numbers called nums and another value target, we have to find the number of triples (i < j < k) that exist such that nums[i] + nums[j] + nums[k] < target.So, if the input is like nums = [−2, 6, 4, 3, 8], target = 12, then the output will be 5, as the triplets are: [−2, 6, 4], [−2, 6, 3], [−2, 4, 3], [−2, 4, 8], [−2, 3, 8]To solve this, we will follow these steps −sort the list numsans := 0n := size of numsfor i in range 0 to n−1, ... Read More

Advertisements