# Tag Archives: Segment-Tree

## Queries for the count of even digit sum elements in the given range using Segment Tree.

Given an array arr[] of N elements, the task is to answer Q queries each having two integers L and R. For each query, the… Read More »

## Range Queries to find the Element having Maximum Digit Sum

Given an array Arr of N integers and Q queries, each query having a range from L to R. Find the element having maximum digit… Read More »

## Range Update Queries to XOR with 1 in a Binary Array.

Given a binary array arr[] of size N. The task is to answer Q queries which can be of any one type from below: Type… Read More »

## Queries for elements having values within the range A to B in the given index range using Segment Tree

Given an array arr[] of N elements and two integers A to B, the task is to answer Q queries each having two integers L… Read More »

## Array range queries to count the number of Fibonacci numbers with updates

Given an array arr[] of N integers, the task is to perform the following two queries: query(start, end): Print the number of fibonacci numbers in… Read More »

## Count of divisors of product of an Array in range L to R for Q queries

Given an array arr of size N and Q queries of the form [L, R], the task is to find the number of divisors of… Read More »

## Dynamic Segment Trees : Online Queries for Range Sum with Point Updates

Prerequisites: Segment Tree Given a number N which represents the size of the array initialized to 0 and Q queries to process where there are… Read More »

## Binary Array Range Queries to find the minimum distance between two Zeros

Prerequisite: Segment Trees Given a binary array arr[] consisting of only 0’s and 1’s and a 2D array Q[][] consisting of K queries, the task… Read More »

## Maximum pair sum in the given index ranges of an Array

Given an array arr containing N positive integers and the number of queries Q, for each query task is to find the maximum pair sum… Read More »

## Maximum distance between two 1s in a Binary Array in a given range

Given a binary array of size N and a range in [l, r], the task is to find the maximum distance between two 1s in… Read More »

## Range Sum and Update in Array : Segment Tree using Stack

Given an array arr[] of N integers. The task is to do the following operations: Add a value X to all the element from from… Read More »

## Build a segment tree for N-ary rooted tree

Prerequisite: Segment tree and depth first search. In this article, an approach to convert an N-ary rooted tree( a tree with more than 2 children)… Read More »

## Length of Longest Subarray with same elements in atmost K increments

Given an integer array arr and a number K, the task is to find the length of longest subarray such that all the elements in… Read More »

## Query to check if a range is made up of consecutive elements

Given an array of n non-consecutive integers and Q queries, the task is to check whether for the given range l and r, the elements… Read More »

## Count number of increasing sub-sequences : O(NlogN)

Given an array arr[] of length N, the task is to find the number of strictly increasing sub-sequences in the given array. Examples: Input: arr[]… Read More »