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
Articles by sudhir sharma
Page 90 of 98
Find the number of different numbers in the array after applying the given operation q times in C++
In this problem, we are given a number N which is the size of an array consisting of all zeros and Q queries each of the following type −update(s, e, val ) -> this query will update all elements from s to e (both inclusive) to val.Our task is to find the number of different numbers in the array after applying the given operation q timesLet’s take an example to understand the problem, Input : N = 6, Q = 2 Q1 = update(1, 4, 3) Q2 = update(0, 2, 4) Output : 2ExplanationInitial array, arr[] = {0, 0, ...
Read MoreFind the number of boxes to be removed in C++
In this problem, we are given an array arr[] in which each element represents a pile of boxes (each of unit height). Our task is to find the number of boxes to be removed.The person is standing at index 0 of the array at the height of the pile of boxes and he needs to move to the end of the array. The condition to move from one pile to the next is by jumping to the next.Jump is possible only when the next pile is at the same height or is at height less than it. If the height ...
Read MoreFind the Nth term of the series 9, 45, 243,1377...in C++
In this problem, we are given an integer value N.Our task is to Find the nth term of the series −9, 45, 243, 1377, 8019, …Let’s take an example to understand the problem,Input : N = 4 Output : 1377Solution ApproachA simple solution to find the problem is by finding the Nth term using observation technique. On observing the series, we can formulate as follow −(11 + 21)*31 + (12 + 22)*32 + (13 + 23)*33 … + (1n + 2n)*3nExampleProgram to illustrate the working of our solution#include #include using namespace std; long findNthTermSeries(int n){ return ( ( (pow(1, n) + pow(2, n)) )*pow(3, n) ); } int main(){ int n = 4; cout
Read MoreFind the nth term of the series 0, 8, 64, 216, 512,... in C++
In this problem, we are given an integer value N. Our task is to find the nth term of the series −0, 8, 64, 216, 512, 1000, 1728, 2744…Let’s take an example to understand the problem, Input: N = 6 Output: 1000Solution ApproachTo find the Nth term of the series, we need to closely observe the series. The series is the cube of even numbers, where the first term is 0.So, the series can be decoded as −[0]3, [2]3, [4]3, [6]3, [8]3, [10]3…For ith term, T1 = [0]3 = [2*(1-1)]3T2 = [2]3 = [2*(2-1)]3T3 = [4]3 = [2*(3-1)]3T4 = [6]3 ...
Read MoreFind the nth term of the given series 0, 0, 2, 1, 4, 2, 6, 3, 8, 4... in C++
In this problem, we are given an integer value N. Our task is to Find the nth term of the given series −0, 0, 2, 1, 4, 2, 6, 3, 8, 4, 10, 5, 12, 6, 14, 7, 16, 8, 18, 9, 20, 10… Let’s take an example to understand the problem, Input − N = 6 Output − 2Solution ApproachTo find the Nth term of the series, we need to closely observe the series. It is the mixture of two series and odd and even terms of the series. Let’s see each of them, At even positions −T(2) = 0T(4) ...
Read MorePractice Questions on Time Complexity Analysis in C++
Time complexity of any algorithm is the time taken by the algorithm to complete. It is an important metric to show the efficiency of the algorithm and for comparative analysis. We tend to reduce the time complexity of algorithm that makes it more effective.Example 1Find the time complexity of the following code snippetsfor(i= 0 ; i < n; i++){ cout
Read MoreFind next palindrome prime in C++
In this problem, we are given an element N. We need to find the next palindrome prime.Problem Description − We need to find the smallest prime number which is also a palindrome number, greater than N.Palindrome Number is a number in which the numbers are the same in both directions.Prime Number is a number if its only factors are 1 and itself.Let’s take an example to understand the problem, InputN = 12Output101ExplanationThe series of palindromes greater than 12 are 22, 33, 44, 55, 66, 77, 88, 99, 101… out of these the smallest palindrome is 101.Solution ApproachA simple solution to ...
Read MoreFind maximum sum array of length less than or equal to m in C++
In the problem, we are given n arrays of different length. Our task is to Find the maximum sum array of length less than or equal to m.We need to find sub-arrays from the arrays to maximise the sum and make the length of all subarrays combined equal to m.Let’s take an example to understand the problem, Inputn = 3, m = 4 arrOfArr[][] = { {5, 2, -1, 4, -3} {3, -2, 1, 6} {-2, 0, 5} }Output20ExplanationSubArrays are {5, 4}, {6}, {5}, length = 2 + 1 + 1 = 4 Sum = 5 + ...
Read MorePrinciples of Risk Management and Paradigm in C++
Risk Management is the approach that is used to manage all available resources and make the best use of the resources available in the system.The project manager will analyse risks from all categories and there might be some risks in the working of the project in the runtime environment.Principles of Risk ManagementThere are 5 basic principles of Risk management. They are:GLOBAL PERSPECTIVE: This risk analysis of software in context of system and business problems planned to be solved. This analysis takes underconsideration the larger system definition, design and implementation.FORWARD LOOKING VIEW: This analysis considers all possible solutions to future risks to the product. Here, ...
Read MoreFile opening modes(r versus r+) in C++
File handling in programming languages is very important for the interaction of programming with the memory for accessing files and fetching data in it.Using a program, you can read data from a file as well as write data to the file and do a lot more functions.Here, we will see reading of data from a file.In programming, before performing any operation you need to open the file. And there are multiple modes to open a file in the programming language. The access to the file is based on the mode it is opened with.Here we will learn about the difference between ...
Read More