# Category Archives: Algorithms

## XOR and OR of all N-digit palindrome number

Given an integer N. The task is to find the XOR and OR of all N digit palindromic numbers. Examples Input: 3 Output: XOR =… Read More »

## Count of sticks required to represent the given string

Given a string str of uppercase alphabets and numbers, the task is to find the number of matchsticks required to represent it. Examples: Input: str… Read More »

## Selection Algorithms

Selection Algorithm is an algorithm for finding the kth smallest (or largest) number in a list or an array. That number is called the kth… Read More »

## Count number of pairs with positive sum in an array

Given an array arr[] of N integers, the task is to count the number of pairs with positive sum. Examples: Input: arr[] = {-7, -1,… Read More »

## Sum of all palindromic numbers lying in the range [L, R] for Q queries

Given Q queries in the form of 2D array arr[][] whose every row consists of two numbers L and R which denotes the range [L,… Read More »

## Count of sub-strings with equal consecutive 0’s and 1’s

Given a binary string str of 0’s and 1’s only. The task is to count the total numbers of substrings of string str such that… Read More »

## First Come, First Serve – CPU Scheduling | (Non-preemptive)

Prerequisite: CPU Scheduling in Operating Systems Given N processes with their Arrival Time as at[] and Burst Time as bt[]. The task is to find… Read More »

## Longest alternating subsequence in terms of positive and negative integers

Given an array arr[] of positive and negative numbers only. The task is to find the length of the longest alternating (means negative-positive-negative or positive-negative-positive)… Read More »

## Count of pairs in an array whose product is a perfect square

Given an array arr[] of N integers, the task is to find the number of pairs (arr[i], arr[j]) such that arr[i]*arr[j] is a perfect square.… Read More »

Prerequisite: Operator Overloading in C++, Linked List in C++ C++ comes with libraries that provide ways for performing Input and Output. In C++, Input and… Read More »

## Value of Pi(Π) up to 50 decimal places

Given a number N(where N <= 50), the task is to find the value of Pi (Π) up to N decimals places. Examples Input: N… Read More »

## Shortest Path Faster Algorithm

Prerequisites: Bellman-Ford Algorithm Given a directed weighted graph with V vertices, E edges and a source vertex S. The task is to find the shortest… Read More »

## Highest power of 2 less than or equal to given Integer

Given an integer N, the task is to find the highest power of 2 that is smaller than or equal to N. Examples: Input: N… Read More »

## Sideways traversal of a Complete Binary Tree

Given a Complete Binary Tree, the task is to print the elements in the following pattern. Let’s consider the tree to be: The tree is… Read More »

## Golomb Sequence | Set 2

Given a number N. The task is to find the first N terms of the Golomb Sequence. Golomb sequence is a non-decreasing integer sequence where… Read More »