File tree 1 file changed +91
-0
lines changed
1 file changed +91
-0
lines changed Original file line number Diff line number Diff line change
1
+ '''
2
+ Number occurring maximum times
3
+ Given a list of N integers sorted in ascending order, Please find the number which occurs 4 times in the array
4
+
5
+ Input
6
+ First number is N (the number of integers given) Followed by the N numbers
7
+
8
+ Output
9
+ Print the number which occurs 4 times. print -1 if such a number doesnt exist
10
+
11
+ Example
12
+ Input: 10
13
+
14
+ 1
15
+
16
+ 2
17
+
18
+ 3
19
+
20
+ 4
21
+
22
+ 4
23
+
24
+ 4
25
+
26
+ 4
27
+
28
+ 5
29
+
30
+ 6
31
+
32
+ 6
33
+
34
+ Output: 4
35
+
36
+ '''
37
+ '''
38
+ def occurence_check(list):
39
+ l=sorted(list)
40
+ prev=l[0]
41
+ ma=False
42
+ count=0
43
+ l2=0
44
+ for i in range(0,len(l)):
45
+ print(i)
46
+ if (prev==l[i]):
47
+ count+=1
48
+ if(count==4):
49
+ l2=prev
50
+ ma=True
51
+ else:
52
+ prev=l[i+1]
53
+ count=0
54
+
55
+ if ma:
56
+ return l2
57
+ else:
58
+ return-1
59
+
60
+
61
+
62
+
63
+ if __name__ == "__main__":
64
+ n=int(input())
65
+ numbers = []
66
+ for i in range(n):
67
+ numbers.append(int(input()))
68
+
69
+ print(occurence_check(numbers))
70
+ '''
71
+ n = int (input ())
72
+ s = [int (input ()) for i in range (n )]
73
+ count = 0
74
+ prev = s [0 ]
75
+ m = True
76
+ b = []
77
+ for i in range (0 ,n ):
78
+ if (prev == s [i ]):
79
+ count += 1
80
+ if count == 4 :
81
+ print (s [i ])
82
+ m = False
83
+ else :
84
+ prev = s [i + 1 ]
85
+ count = 0
86
+
87
+ if m :
88
+ print (- 1 )
89
+
90
+ ''''''
91
+
You can’t perform that action at this time.
0 commit comments