
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 33676 Articles for Programming

142 Views
In this tutorial, we will be discussing a program to find queries to return the absolute difference between L-th smallest number and the R-th smallest number.For this we will be provided with an array containing integers and Q queries. Our task is to find the absolute difference between the indices of Lth smallest and Rth smallest values.Example Live Demo#include using namespace std; //returning the result of a query int respondingQuery(pair arr[], int l, int r) { int result = abs(arr[l - 1].second - arr[r - 1].second); return result; } //implementing the queries void calcDifference(int givenarr[], int a, int ... Read More

195 Views
In this tutorial, we will be discussing a program to find querying the number of distinct colors in a subtree of a colored tree using BIT.For this we will be provided with rooted tree where each node has a color denoted by given array. Our task is to find all the distinct coloured nodes below the given node in the tree.Example Live Demo#include #define MAXIMUM_COLOUR 1000005 #define MAXIMUM_NUMBER 100005 using namespace std; vector tree[MAXIMUM_NUMBER]; vector table[MAXIMUM_COLOUR]; int isTraversing[MAXIMUM_COLOUR]; int bit[MAXIMUM_NUMBER], getVisTime[MAXIMUM_NUMBER], getEndTime[MAXIMUM_NUMBER]; int getFlatTree[2 * MAXIMUM_NUMBER]; bool vis[MAXIMUM_NUMBER]; int tim = 0; vector< pair< pair, int> > queries; //storing results of ... Read More

133 Views
In this tutorial, we will be discussing a program to find queries to update a given index and find gcd in range.For this we will be provided with an array containing integers and Q queries. Our task is to find the result of given queries (updating a given value by X, finding the gcd between two given values).Example Live Demo#include using namespace std; //getting middle index int findMiddle(int s, int e) { return (s + (e - s) / 2); } //updating values at given indices void updateIndexValue(int* st, int ss, int se, int i, int diff, int si) ... Read More

103 Views
In this tutorial, we will be discussing a program to find time taken for signal to reach all positions in a stringFor this we will be provided with a string containing ‘x’ and ‘o’. A signal originates from ‘x’ and travels in both directions changing one ‘o’ value in one unit time. Our task is to calculate the complete time to convert whole string into ‘x’s.Example Live Demo#include using namespace std; //calculating the total required time int findMaximumDuration(string s, int n) { int right = 0, left = 0; int count = 0, maximumLength = INT_MIN; s ... Read More

171 Views
In this tutorial, we will be discussing a program to find two numbers with sum and product both same as N.For this we will be provided with an integer value. Our task is to find two other integer values whose product and sum is equal to the given value.Example Live Demo#include using namespace std; //finding a and b such that //a*b=N and a+b=N void calculateTwoValues(double N) { double val = N * N - 4.0 * N; if (val < 0) { cout

107 Views
In this tutorial, we will be discussing a program to find triplet such that number of nodes connecting these triplets is maximum.For this we will be provided with a tree with N nodes. Our task is to find a triplet of nodes such that the nodes covered in the path joining them in maximum.Example Live Demo#include #define ll long long int #define MAX 100005 using namespace std; vector nearNode[MAX]; bool isTraversed[MAX]; //storing the required nodes int maxi = -1, N; int parent[MAX]; bool vis[MAX]; int startnode, endnode, midNode; //implementing DFS to search nodes void performDFS(int u, int count) { ... Read More

159 Views
In this tutorial, we will be discussing a program to find trace of matrix formed by adding Row-major and Column-major order of same matrix.For this we will be provided with two arrays one in row-major and other in columnmajor. Our task is to find the trace of the matrix formed by the addition of the two given matrices.Example Live Demo#include using namespace std; //calculating the calculateMatrixTrace of the new matrix int calculateMatrixTrace(int row, int column) { int A[row][column], B[row][column], C[row][column]; int count = 1; for (int i = 0; i < row; i++) for ... Read More

176 Views
In this tutorial, we will be discussing a program to find uncommon characters of the two strings.For this we will be provided with two strings. Our task is to print out the uncommon characters of both strings in sorted order.Example Live Demo#include using namespace std; const int LIMIT_CHAR = 26; //finding the uncommon characters void calculateUncommonCharacters(string str1, string str2) { int isthere[LIMIT_CHAR]; for (int i=0; i

154 Views
In this tutorial, we will be discussing a program to find two distinct prime numbers with given product.For this we will be provided with an integer value. Our task is to find the two prime integer values such that their product is equal to the given value.Example Live Demo#include using namespace std; //generating prime numbers less than N. void findingPrimeNumbers(int n, bool calcPrime[]) { calcPrime[0] = calcPrime[1] = false; for (int i = 2; i

2K+ Views
To find the maximum element in an array, the PHP code is as follows −Example Live DemoOutputThe highest value of the array is91A function named ‘get_max_value()’ is defined, that takes an array as parameter. Inside this function, the count function is used to find the number of elements in the array, and it is assigned to a variable −$n = count($my_array);The first element in the array is assigned to a variable, and the array is iterated over, and adjacent values in the array are compared, and the highest value amongst all of them is given as output −$max_val = $my_array[0]; for ... Read More