
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 26504 Articles for Server Side Programming

642 Views
You are given an array and the index of the target element. We have to count the number of elements greater than the given element to its right. Let's see an example.Inputarr = [2, 3, 5, 1, 4, 2, 6] index = 3Output3The target index element is 1. There are three elements i.e..., 4, 2, 6 that are greater than 1 on its right side.AlgorithmInitialise the array and index of target element.If the index is greater than or equal to the length of the array, then return -1.Write a loop that iterates from the next element of the given index.Increment ... Read More

204 Views
The stepping number is a number where the difference between the consecutive digits is 1. You are given a number n representing the number of digits. You need to count the total number of stepping numbers with n digits.Let's see an example.Input2Output17The lowest number of 2 digits is 10 and highest number of 2 digits is 99. There are 17 stepping numbers in between them.AlgorithmInitialise the number n.Initialise the count to 0.Find the lowest number of n digits i.e.., pow(10, n - 1).Find the highest number of n digits i.e.., pow(10, n) - 1.Write a loop that iterates from the ... Read More

149 Views
Given a number N, we need to find the moves required to guess the permutation in the worst-case scenario. The number of moves required to guess the permutation will be n!. Let's take an example.Input5Output129When we have 5 elements, then we have 5 ways to guess, and 4 ways when we have 4 elements and it continuous till 1.AlgorithmInitialise the number n.Initialise count to 1.Write a loop that iterates from 1 to n.Multiply count with the current number.Return the count.ImplementationFollowing is the implementation of the above algorithm in C++#include using namespace std; int getNumberMoves(int n) { int count ... Read More

441 Views
In this tutorial, we are going to write a program that finds the number of leaf nodes for every node in the n-ary tree.Given a n-ary tree, we have to find the number of leaf nodes for every subtree. Let's see an example.InputN = 8 tree = [[2, 3], [], [4, 5, 6], [7, 8], [], [], [], []]Output1->5 2->1 3->4 4->2 5->1 6->1 7->1 8->1AlgorithmInitialise the n-ary tree with tree you like.Use the DFS to traverse through the tree.Maintain an array to store the count of each node leaf nodes count.Increment the count of leaf node after the recursive ... Read More

613 Views
Given a number, we have to find the number of leading zeroes in the binary representation of it. Assuming total bits to be 32. Let's see an example.Input5Output25The binary representation of 5 is 00000...00101. The number of leading zeroes are 29.AlgorithmInitialise the number n.Find the binary representation of n.Subtract the length of binary representation of n from the total number of bits i.e.., 32.Return the result.ImplementationFollowing is the implementation of the above algorithm in C++#include using namespace std; int getLeadingZeroesCount(unsigned int n) { int totalBits = sizeof(n) * 8; string binary = ""; while (n) { ... Read More

175 Views
Given a string, we have to count the number of larger elements on right side of each character. Let's see an example.Inputstring = "abc"Output2 1 0There are 2 larger elements than a on its right side.There is 1 larger element than b on its right side.There are 0 larger elements than c on its right side.AlgorithmInitialise the string.Initialise an array to keep track of the count.Write two loops to iterate over the string.Take one char at a time and compare it with all the character after it.Increment the corresponding character count in the count array if the current element is ... Read More

386 Views
The solutions for the equation areThe number of non-negative integral solutions of the equation are $\left(\begin{array}{c}n-k+1\ k\end{array}\right)$The number of positive integral solutions of the equation are $\left(\begin{array}{c}k-1\ n-1\end{array}\right)$Add both to get the required answer. Let's see an example.Inputn = 4 k = 7Output140 AlgorithmInitialise the numbers n and k.Find the integral solutions of not-negative and positive numbers.Add both of them.Return the answer.ImplementationFollowing is the implementation of the above algorithm in C++#include using namespace std; int factorial(int n) { int product = 1; for (int i = 2; i Read More

570 Views
In this tutorial, we are going to write a program the finds the number of integral points between the given two points.The number of points between two given points will be gcd(abs(x2), abs(y1-y2)) - 1.If the line joining is parallel to x-axis, then the number of integral points will be abs(y1 - y2) - 1.If the line joining is parallel to y-axis, then the number of integral points will be abs(x1 - x2) - 1If the x points of both points are equal, then they are parallel to the x-axis. If the y points of both points are equal, then ... Read More

390 Views
Given a number n, we have to find the number of integers with an odd number of set bits in their binary form. Let's see an example.Inputn = 10Output5There are 5 integers from 1 to 10 with odd number of set bits in their binary form.AlgorithmInitialise the number N.Write a function to count the number of set bits in binary form.Initialise the count to 0.Write a loop that iterates from 1 to N.Count the set bits of each integer.Increment the count if the set bits count is odd.Return the count.ImplementationFollowing is the implementation of the above algorithm in C++#include ... Read More

172 Views
You are given an array, and indexes range. You need to count the total number of adjacent elements that are equal in the given range.Let's see an example.Inputarr = [1, 2, 2, 2, 3, 3, 4] lower = 1 upper = 5Output3AlgorithmInitialise the array and indexes range.Write a loop that iterates from the lower index of the range to upper index of the range.Compare the element the previous or next element.Increment the count if they are equal.Return the count.ImplementationFollowing is the implementation of the above algorithm in C++#include using namespace std; int getEqualElementsCount(int arr[], int n, int lower, int ... Read More