Little Shino and Pairs
Practice
3.9 (90 votes)
Approved
Data structures
Easy
Stacks
Problem
24% Success 18378 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
Given a permutation of number from 1 to N. Among all the subarrays, find the number of unique pairs \((a, b)\) such that \(a \neq b\) and a is maximum and b is second maximum in that subarray.
Input:
First line contains an integer, N \((1 \le N \le 10^5)\). Second line contains N space separated distinct integers, \(A_i\) \((1 \le A_i \le N)\), denoting the permutation.
Output:
Print the required answer.
Submissions
Please login to view your submissions
Similar Problems
Points:20
48 votes
Tags:
Data StructuresEasyHiringQueueStacks
Points:20
53 votes
Tags:
Data StructuresDynamic programmingEasyStacks
Points:20
78 votes
Tags:
ArraysBasic ProgrammingData StructuresEasyImplementationStackseasy
Editorial