Skip to content

Commit 406a10c

Browse files
added a new question
1 parent 9cb64e8 commit 406a10c

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

Dominant Element.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""
2+
Question Name: Dominant Element
3+
4+
5+
You are given an array A consisting of N positive integers. The ith element of the array is called Dominant if :
6+
7+
1. Let B be an array formed by removing Ai from array A.
8+
Like if A = [5 1 2 3 2] and i=3, B will be = [5 1 3 2].
9+
10+
2. Now Ai is dominant if it is possible to rearrange elements of array B such that Ai+j > Bj holds for all 1<=j<=length of array B.
11+
12+
Like if Ai = 2 and B = [3 1 2], Ai is dominant.
13+
THis is because if we rearrange elements of array B as [2 1 3], A1+1 > B1, A2+2 > B2 and A3+3 > B3 holds.
14+
Given array A, print the number of Dominant elements in array A.
15+
16+
17+
Input Format
18+
19+
First line contains a single integer denoting N.
20+
Next line contains N space separated integers denoting the elements of array A.
21+
22+
23+
Output Format
24+
25+
Print the number of Dominant elements in array A.
26+
27+
28+
Constraints
29+
30+
1<=N<=10^5
31+
1<=Ai<=N
32+
33+
34+
Sample Input 1
35+
36+
5
37+
5 1 4 3 2
38+
39+
Sample Output 1
40+
41+
2
42+
43+
Explanation of Sample 1
44+
45+
The 1st and 3rd elements of the array are Dominant.
46+
For i=1, B = [1 4 3 2]. Here 5+1>1, 5+2>4, 5+3>3 and 5+4>2 holds.
47+
For i=3, B = [5 1 3 2]. Rearrange array B as [2 3 1 5]. Here 4+1>2, 4+1>3, 4+3>1, 4+4>5 holds.
48+
49+
"""
50+

0 commit comments

Comments
 (0)