Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Programming Articles
Page 403 of 2544
Find multiplication of sums of data of leaves at same levelss in C++
ConceptWith respect of a given Binary Tree, return following value for it.With respect of every level, calculate sum of all leaves if there are leaves at this level. Else ignore it.Calculate multiplication of all sums and return it.InputRoot of following tree 3 / \ 8 6 \ 10Output80First level doesn’t have leaves. Second levelhas one leaf 8 and third level also has one leaf 10. So result is 8*10 = 80InputRoot of following tree 3 ...
Read MoreUnique Morse Code Words in Python
Suppose we have a list of words, here each word can be written as a concatenation of the Morse code of each letter. For example, the word "cba" can be written as "-.-..--...", this is the concatenation "-.-." | "-..." | ".-"). This kind of concatenation is called the transformation of a word.We know that International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: "a" maps to ".-", "b" maps to "-...", "c" maps to "-.-.", and so on.Here is the list of all 26 letters of the ...
Read MoreMaximum subarray size, such that all subarrays of that size have sum less than k in C++
In this tutorial, we will be discussing a program to find maximum subarray size, such that all subarrays of that size have sum less than k.For this we will be provided with an array of size N and an integer k. Our task is to find the length of subarray such that all the sub-arrays of that length in the given array sum to be less than or equal to k.Example#include using namespace std; //finding maximum length subarray int bsearch(int prefixsum[], int n, int k) { int ans = -1; //performing binary search int left = 1, ...
Read MoreWord Squares in C++
Suppose we have a set of words (all are unique), we have to find all word squares and we can build from them. Here a sequence of words forms a valid word square if the kth row and column read the exact same string, where 0 ≤ k < maximum of numRows and numColumns. So as an example, the word sequence ["ball", "area", "lead", "lady"] will construct a word square because each word reads the same both horizontally and vertically.ballarealeadladySo, if the input is like ["area", "lead", "wall", "lady", "ball"], then the output will be [[ "wall", "area", "lead", "lady"], ...
Read MoreJava Program to find the vertex, focus and directrix of a parabola
Following is the Java program to find the vertex, focus and directrix of a parabola −Examplepublic class Demo{ public static void find_values(float val_1, float val_2, float val_3){ System.out.println("The value of vertex is (" + (-val_2 / (2 * val_1)) + ", "+ (((4 * val_1 * val_3) - (val_2 * val_2)) / (4 * val_1)) + ")"); System.out.println("The value of focus is (" + (-val_2 / (2 * val_1)) + ", " + (((4 * val_1 * val_3) - (val_2 * val_2) + 1) / (4 * val_1)) + ")"); ...
Read MoreFind n-th lexicographically permutation of a strings in C++
ConceptWith respect of a given string of length m containing lowercase alphabets only, our task to determine the n-th permutation of string lexicographically.Inputstr[] = "pqr", n = 3OutputResult = "qpr"ExplanationAll possible permutation in sorted order − pqr, prq, qpr, qrp, rpq, rqpInputstr[] = "xyx", n = 2OutputResult = "xyx"ExplanationAll possible permutation in sorted order − xxy, xyx, yxxMethodHere we use some Mathematical concept for solving this problem.The concept is based on following facts.Here, the total number of permutation of a string generated by N characters (all distinct) is N!Now, the total number of permutation of a string generated by N ...
Read MoreBitwise recursive addition of two integers in C
In this problem, we are given two numbers. Our task is to create a C program for the Bitwise recursive addition of two integers.The logic to find the sum using the Bitwise operations is similar to what we used to do when we were in preschool. For finding the sum, we used to add each digit of the number and if a carry is there, we add it to the next digit.We will do a similar thing, find the sum using the XOR operator and check for the carry using the AND operation. If there is a carry we will ...
Read MoreMaximum subarray sum in an array created after repeated concatenation in C++
In this tutorial, we will be discussing a program to find maximum subarray sum in an array created after repeated concatenation.For this we will be provided with an array and an integer K. Our task is to find the subarray with the maximum elements when the given array is repeated K times.Example#include using namespace std; //returning sum of maximum subarray int maxSubArraySumRepeated(int a[], int n, int k) { int max_so_far = INT_MIN, max_ending_here = 0; for (int i = 0; i < n*k; i++) { max_ending_here = max_ending_here + a[i%n]; if (max_so_far ...
Read MoreEncode N-ary Tree to Binary Tree in C++
Suppose we have a N-ary tree. We have to encode that tree into one binary. We also have to make deserializer to deserialize the binary tree to N-ary tree.So, if the input is likethen the output will beTo solve this, we will follow these steps −Define a function encode(), this will take root, if root is valid, then −return nullnode = new tree node with value of rootif size of children of root is not 0, then −left of node := encode(children[0] of root)curr = left of nodefor initialize i := 1, when i < size of children of root, ...
Read MoreFind nth term of a given recurrence relation in C++
ConceptAssume bn be a sequence of numbers, which is denoted by the recurrence relation b1=1 and bn+1/bn=2n. Our task is to determine the value of log2(bn) for a given n.Input6Output15Explanationlog2(bn) = (n * (n - 1)) / 2 = (6*(6-1))/2 = 15Input200Output19900Methodbn+1/bn = 2nbn/bn-1 = 2n-1...b2/b1 = 21, We multiply all of above in order to attain(bn+1/bn).(bn/n-1)……(b2/b1) = 2n + (n-1)+……….+1So, bn+1/b1 = 2n(n+1)/2Because we know, 1 + 2 + 3 + ………. + (n-1) + n = n(n+1)/2So, bn+1 = 2n(n+1)/2 . b1; Assume the initial value b1 = 1So, bn+1 = 2sup>n(n+1)/2Now substituting (n+1) for n, we get, ...
Read More