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
-
Economics & Finance
Programming Articles
Page 2092 of 2547
Find the Initial Array from given array after range sum queries in C++
In this problem, we are given an array res[] of size N. Our task is to find the Initial Array from given array after range sum queries.We need to find the starting array which will return the array rel[] on performing [s, e, val] query on it.Each [s, e, val] query is solved ass -> starting indexe -> ending indexval -> update value to be added to each element from s to e in array.Let's take an example to understand the problem, Input : rel[] = {7, 4, 8} Query[][] = {{1, 2, 1}, {0, 1, 3}} Output : {4, ...
Read MoreFind the index of the left pointer after possible moves in the array in C++
In this problem, we are given an array arr[] of size N. Our task is to find the index of the left pointer after possible moves in the array.We have two pointers for the array, one left pointer and another right pointer.Left pointer starts at index 0 and the value is incremented.Right pointer starts at index (n-1) and the value is decremented.The value of a pointer increases if the sum traversed is lesser than other, i.e. if left pointer's sum is less than right pointer's sum, left pointer is increased otherwise right pointer is decreased. And sum's are updated.Let's take ...
Read MoreFind the index of first 1 in a sorted array of 0's and 1's in C++
In this problem, we are given an array bin[] consisting of boolean values (only 0's and 1's) in sorted order. Our task is to find the index of first 1 in a sorted array of 0's and 1's.Let's take an example to understand the problem, Input : bin[] = {0, 0, 0, 1, 1} Output : 3Explanation −First 1 of the binary array is encountered at index 3.Solution ApproachTo solve the problem, we basically need to find the index of 1st 1 in the array. For that we can use a searching technique.One approach can be using linear search, we ...
Read MoreFind the hypotenuse of a right angled triangle with given two sides in C++
In this problem, we are given two integer values H and B defining height and base of a right angled triangle. Our task is to find the hypotenuse of a right angled triangle with given two sides.Right Angled Triangle is a special triangle whose two angles are at right angles.Let's take an example to understand the problem, Input : B = 5, H = 12 Output : 13.00Solution ApproachA simple solution to the problem is using the concept of pythagoras theorem to find the hypotenuse of a triangle using the base and height.Pythagoras Theorem States that the square of the ...
Read MoreFind the first repeating element in an array of integers C++
In this problem, we are an array arr of n integer values. Our task is to find the first repeating element in an array of integers.We need to find the first integer value from the array which occurred more than once in the array.Let's take an example to understand the problem, Input : arr[] = {4, 1, 8, 9, 7, 2, 1, 6, 4} Output : 4Explanation −Integers with more than one occurrence are 4 and 1. 4's first occurrence is smaller than 1. Hence the answer is 4Solution ApproachA simple solution to the problem is using nested loops. We ...
Read MoreFind the first repeated word in a string in C++
In this problem, we are a string str consisting of comma separated words. Our task is to find the first repeated word in a string.We need to find the first word 'string between two spaces' which gets repeated in the string.Let's take an example to understand the problem, Input : str = "C program are easy to program" Output : programSolution ApproachA simple solution to the problem is using hashmap data structure. To find the first repeated word, we will store each word and its count (number of times it appeared in the string ) in the hashmap. For this ...
Read MoreFind the first maximum length even word from a string in C++
In this problem, we are a string str consisting of comma separated words. Our task is to find the first maximum length, even word, from a string.We need to find the largest word 'string between two spaces' whose length is maximum and even.Let's take an example to understand the problem, Input : str = "learn programming at TutorialsPoint" Output : TutorialsPointExplanation −The string with even length is TutorialsPoint. Solution ApproachA simple solution to the problem is by simply finding the string which has even length greater than the current string. Initialise the maxString length to 0.AlgorithamStep 1 − Iterate over ...
Read MoreFind the Deepest Node in a Binary Tree in C++
In this problem, we are given a binary tree. Our task is to find the Deepest Node in a Binary Tree.Binary Tree is a special data structure used for data storage purposes. A binary tree has a special condition that each node can have a maximum of two children.Deepest node in a binary tree is the node which is at the maximum possible height in the tree.Let's take an example to understand the problem, Input :Output : 8Solution ApproachThere can be multiple ways to solve this problem, as you need to find the height and traverse the tree to the ...
Read MoreFind the average of first N natural numbers in C++
In this problem, we are given a number n. Our task is to find the average of first N natural numbers.Average of numbers is defined as the sum of all numbers divided by the total number of numbers.Average of N natural numbers is defined as the sum of first N natural numbers divided by N.Let's take an example to understand the problem, Input : N = 23 Output : 12Explanation −1 + 2 + 3 + ... + 22 + 23 = 276 276 / 23 = 12Solution ApproachTo find the average of the number we will use the formula ...
Read MoreFind the arrangement of queue at given time in C++
In this problem, we are given a string consisting of characters 'M' and 'F' only and a time t. Our task is to find the arrangement of the queue at a given time.The string defines people standing in a common queue to enter the bus. All males in the queue are so chivalrous that if they see a female behind them at any point of time they exchange places with them. There is t unit time left to enter the bus and each exchange takes one unit time. We need to find the positions when the bus comes by rearranging ...
Read More