Sudhir sharma has Published 1149 Articles

Find sum of all right leaves in a given Binary Tree in C++

sudhir sharma

sudhir sharma

Updated on 25-Jan-2022 14:01:09

428 Views

In this problem, we are given a binary tree. Our task is to find the sum of all left right in a given Binary Tree.Let's take an example to understand the problem, Input :Output : 8Explanation −All leaf nodes of the tree are : 1, 8 Sum = 1 + ... Read More

Find sum of all left leaves in a given Binary Tree in C++

sudhir sharma

sudhir sharma

Updated on 25-Jan-2022 13:26:08

397 Views

In this problem, we are given a binary tree. Our task is to find the sum of all left leaves in a given Binary Tree.Let's take an example to understand the problem, Input : Output : 11Explanation −All leaf nodes of the tree are : 2, 9 Sum = 2 + ... Read More

Find subarray with given sum - (Handles Negative Numbers) in C++

sudhir sharma

sudhir sharma

Updated on 25-Jan-2022 13:06:14

591 Views

In this problem, we are given an array arr[] consisting of N integers stored in unsorted order. Our task is to find a subarray with a given sum.Let's take an example to understand the problem, Input : arr[] = {2, 5, -1, 4, 6, -9, 5} sum = 14 Output ... Read More

Find subarray with given sum - (Nonnegative Numbers) in C++

sudhir sharma

sudhir sharma

Updated on 25-Jan-2022 12:52:30

413 Views

In this problem, we are given an array arr[] consisting of N positive integers stored in unsorted order. Our task is to find a subarray with a given sum.Let's take an example to understand the problem, Input : arr[] = {2, 5, 1, 4, 6, 9, 5} sum = 11 ... Read More

Find sub-string with given power in C++

sudhir sharma

sudhir sharma

Updated on 25-Jan-2022 12:06:06

259 Views

In this problem, we are given a string str and an integer pow. Our task is to find a sub-string with given power.We need to return the substring whose power is equal to pow.Power of string is the sum of powers of its characters.Power of character : a -> 1, ... Read More

Find sub-matrix with the given sum in C++

sudhir sharma

sudhir sharma

Updated on 25-Jan-2022 11:16:54

1K+ Views

In this problem, we are given a 2D matrix of size N*N and two variables sum and size. Our task is to find a sub-matrix with the given sum.We need to find a sub-matrix of size*size with element sum equal to sum.Let's take an example to understand the problem, Input ... Read More

Find start and ending index of an element in an unsorted array in C++

sudhir sharma

sudhir sharma

Updated on 25-Jan-2022 08:48:09

933 Views

In this problem, we are given an array aar[] of n integer values which are not sorted and an integer val. Our task is to find the start and ending index of an element in an unsorted array.For the occurrence of the element in the array, we will return, "Starting ... Read More

Find Square Root under Modulo p (Shanks Tonelli algorithm) in C++

sudhir sharma

sudhir sharma

Updated on 25-Jan-2022 08:28:01

580 Views

In this problem, we are given two values n and a prime number p. Our task is to find Square Root under Modulo p.Let's take an example to understand the problem, Input : n = 4, p = 11 Output : 9Solution ApproachHere, we will be using Tonelli-Shanks Algorithm.Tonelli-Shanks Algorithm ... Read More

Find Square Root under Modulo p (When p is in form of 4*i + 3) in C++

sudhir sharma

sudhir sharma

Updated on 25-Jan-2022 07:46:35

140 Views

In this problem, we are given two values n and a prime number p. Our task is to find Square Root under Modulo p (When p is in form of 4*i + 3). Here, p is of the form (4*i + 3) i.e. p % 4 = 3 for i ... Read More

Find the number of primitive roots modulo prime in C++.

sudhir sharma

sudhir sharma

Updated on 24-Jan-2022 13:34:13

761 Views

In this problem, we are given a prime number N. Our task is to find the number of primitive roots modulo prime.Primitive Root of a number − It is a number (r) smaller than N which has all values of r^x(mod N) different for all X in range [0, n-2].Let’s take ... Read More

Advertisements