Shubham and Subarrays
Practice
3 (20 votes)
Data structures
Easy
Hash tables
Problem
66% Success 4888 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given an array consisting of n integer numbers \(a_1,a_2..a_n\). Two subarrays \([l_1
\space r_1]\) (\(1\le l_1\le r_1\le n\)) and \([l_2 \space r_2]\) (\(1\le l_2\le r_2\le n\)) are considered the same if they have the same "special set" of numbers. Output the number of distinct subarrays.
Note: A "special set" of numbers is a set of unique numbers sorted in increasing order.For example,the "special set" corresponding to the numbers [\(5,2,7,2,5,9\)] is [\(2,5,7,9\)].
Input Format
First line contains n denoting the number of array elements.
Second line contains n integers denoting \(a_1,a_2..a_n\)
Output Format
Output the required answer.
Constraints
\(1\le n\le 1000\)
\(1\le a_i\le 1000 \)
Submissions
Please login to view your submissions
Similar Problems
Points:30
27 votes
Tags:
EasyHash TablesMath
Points:30
118 votes
Tags:
EasyHash MapsHashing algorithmString Manipulation
Editorial