Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • DSA
  • Interview Questions on Array
  • Practice Array
  • MCQs on Array
  • Tutorial on Array
  • Types of Arrays
  • Array Operations
  • Subarrays, Subsequences, Subsets
  • Reverse Array
  • Static Vs Arrays
  • Array Vs Linked List
  • Array | Range Queries
  • Advantages & Disadvantages
Open In App
Next Article:
Mean of range in array
Next article icon

Array Range Queries

Last Updated : 23 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The array range query problem can be defined as follows:

Given an array of numbers, the array range query problem is to build a data structure that can efficiently answer queries of a particular type mentioned in terms of an interval of the indices.

The specific query can be of type - maximum element in the given range, most frequent element in the given range or queries like these.

Types of Array Range Queries:

Array range queries can be classified based on the type of input provided and on the type of output:

1. Based on the type of input:

  • The value of interest is completely determined by the problem, in this case, the query consists of only a range of indices.
  • A single value of interest is provided in the query.
  • The query consists of a threshold where all the values above or below the threshold are of interest.
  • The query consists of an exact threshold value.

2. Based on the type of output:

  • Returns a single value matching the criteria.
  • Index of an element that matches the criteria provided in the query.
  • A list of all values that satisfy the given criteria.
  • Only a response like "yes" or "no" denoting if there is any result matching the criteria of the query.

Easy Problems on Array range Queries:

  • Range sum queries without updates
  • Range Queries for Frequencies of array elements
  • Range LCM Queries
  • Count Primes in Ranges
  • Queries for number of distinct elements in a subarray
  • Mean of range in array
  • Check in binary array the number represented by a subarray is odd or even
  • Total numbers with no repeated digits in a range
  • Queries for counts of array elements with values in given range
  • Queries for decimal values of subarrays of a binary array
  • GCDs of given index ranges in an array
  • Queries on probability of even or odd number in given ranges

Medium Problems on Array range Queries:

  • Difference Array | Range update query in O(1)
  • Range sum query using Sparse Table
  • Number of indexes with equal elements in given range
  • Constant time range add operation on an array
  • Number whose sum of XOR with given array range is maximum
  • Number of primes in a subarray (with updates)
  • Print modified array after executing the commands of addition and subtraction
  • Sum of Interval and Update with Number of Divisors
  • Queries on XOR of greatest odd divisor of the range
  • Print modified array after multiple array range increment operations
  • Binary array after M range toggle operations

Hard Problems on Array range Queries:

  • Sparse Table
  • MO’s Algorithm
  • Sqrt (or Square Root) Decomposition Technique | Set 1 (Introduction)
  • Range Minimum Query (Square Root Decomposition and Sparse Table)
  • Number of elements less than or equal to a given number in a given subarray
  • Number of elements less than or equal to a given number in a given subarray | Set 2 (Including Updates)
  • Array range queries over range queries
  • Array range queries for searching an element
  • Maximum Occurrence in a Given Range
  • Merge Sort Tree for Range Order Statistics
  • Count and Toggle Queries on a Binary Array
  • Min-Max Range Queries in Array
  • Range Query on array whose each element is XOR of index value and previous element
  • Count elements which divide all numbers in range L-R
  • Queries for GCD of all numbers of an array except elements in a given range
  • XOR of numbers that appeared even number of times in given Range

Quick Links :

  • 'Practice Problems' on Arrays
  • 'Quizzes' on Arrays
  • 'Video Tutorials' on Arrays

Next Article
Mean of range in array

H

harendrakumar123
Improve
Article Tags :
  • DSA
  • Arrays
  • array-range-queries
Practice Tags :
  • Arrays

Similar Reads

  • Array Rearrangement
    Arrays are fundamental data structures in programming, allowing us to store and manipulate collections of related data. One common operation we may need to perform on arrays is rearranging their elements. Array rearrangement can serve various purposes, such as sorting the elements, reversing the ord
    3 min read
  • Mean of range in array
    Given an array arr[] of n integers and q queries represented by an array queries[][], where queries[i][0] = l and queries[i][1] = r. For each query, the task is to calculate the mean of elements in the range l to r and return its floor value. Examples: Input: arr[] = [3, 7, 2, 8, 5] queries[][] = [[
    12 min read
  • Array range queries over range queries
    Given an array of size n and a give set of commands of size m. The commands are enumerated from 1 to m. These commands can be of the following two types of commands: Type 1 [l r (1 <= l <= r <= n)] : Increase all elements of the array by one, whose indices belongs to the range [l, r]. In th
    15+ min read
  • Java Array Exercise
    An array is a group of elements with similar data types that are bound together as one. The array allows us to store and manipulate a collection of elements together. Mastering arrays is essential for any Java developer, as it provides a solid foundation for more complex data structures and algorith
    7 min read
  • What is Array?
    Array is a linear data structure where all elements are arranged sequentially. It is a collection of elements of same data type stored at contiguous memory locations. For simplicity, we can think of an array as a flight of stairs where on each step is placed a value (let's say one of your friends).
    2 min read
  • Array range queries for searching an element
    Given an array of N elements and Q queries of the form L R X. For each query, you have to output if the element X exists in the array between the indices L and R(included). Prerequisite : Mo's Algorithms Examples : Input : N = 5 arr = [1, 1, 5, 4, 5] Q = 3 1 3 2 2 5 1 3 5 5 Output : No Yes Yes Expla
    15+ min read
  • Searching in Array
    Searching is one of the most common operations performed in an array. Array searching can be defined as the operation of finding a particular element or a group of elements in the array. There are several searching algorithms. The most commonly used among them are: Linear Search Binary Search Ternar
    4 min read
  • Traversal in Array
    Traversal in an array refers to the process of accessing each element in the array sequentially, typically to perform a specific operation, such as searching, sorting, or modifying the elements. Traversing an array is essential for a wide range of tasks in programming, and the most common methods of
    14 min read
  • Query-Based Array Transformation
    Given an array arr[] of size N, initially, all the elements of arr are 0, you have to process q queries of the form "L R X" denoting that fill the array from index l to index r with the number x, the task is to print the final array after all the operations have been performed. Examples: Input: N =
    15 min read
  • Parallel Array
    Parallel Array: Also known as structure an array (SoA), multiple arrays of the same size such that i-th element of each array is closely related and all i-th elements together represent an object or entity. An example parallel array is two arrays that represent x and y co-ordinates of n points. Belo
    15+ min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences