×

# MQRY Editorial

Author and Editorialist : Arun Prasad

EASY

Segment Trees

# PROBLEM:

Given the range of indexes print the difference between the largest and smallest value in the given range

# EXPLANATION:

Create a segment tree for the given array, for each node in the segment tree maintain two variable, one for the smallest value in the sements range and other one for largest value in the segments range.

# Author's Solution :

43914
accept rate: 16%

 2 Sir,I think the cases set were weak. I solved the problem by both the methods-Segment Tree and the naive algorithm(checking over and over again by iterating between the bounds of the query). Segment Tree method was pretty fast - 0.05s Segment tree solution But Naive algorithm also worked - 0.62s Naive Solution Another method worked at 0.24s link Can you tell me the cases set by you for testing the solution so that I can understand the Time taken. Thank You. answered 30 Jun '15, 01:18 534●2●16 accept rate: 12% Thanks For letting me know about this issue.I will try to change the Test Cases . (30 Jun '15, 11:52) Test Cases Updated ! Navie method wont work and will give TLE (01 Jul '15, 22:49)
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×15,482
×3,706
×1,726
×6
×2

question asked: 29 Jun '15, 19:02

question was seen: 2,297 times

last updated: 01 Jul '15, 22:49