File tree 2 files changed +50
-0
lines changed
2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,8 @@ My solutions to competitive programming problems in [Geeks for Geeks](https://au
96
96
| Search in sorted array| [ C++] ( c++/search-in-sorted-array.cpp ) |
97
97
| Insert at end of array| [ C++] ( c++/array-insert-at-end.cpp ) |
98
98
| Equilibrium point| [ C++] ( c++/equilibrium-point.cpp ) |
99
+ | Left index| [ C++] ( c++/left_index.cpp ) |
100
+ | Count only repeated elements| [ C++] ( c++/count-repeated-element.cpp ) |
99
101
| Remove duplicate elements| [ C++] ( c++/remove-duplicate-elements.cpp ) |
100
102
| Search element in array| [ C++] ( c++/search0an0element-in-an-array.cpp ) |
101
103
| Check if two arrays are equals| [ C++] ( c++/check-if-two-arrays-are-equals.cpp ) |
@@ -213,6 +215,7 @@ My solutions to competitive programming problems in [Geeks for Geeks](https://au
213
215
| ----------| :----------------:|
214
216
| Display linked list| [ C++] ( c++/display-linked-list.cpp ) |
215
217
| Sum of nodes| [ C++] ( c++/sum-of-nodes.cpp ) |
218
+ | Linked list insert| [ C++] ( c++/linked-list-insert.cpp ) |
216
219
| Sorted insert for circular linked list| [ C++] ( c++/sorted-insert-for-circular-linked-list.cpp ) |
217
220
| Join two linked list| [ C++] ( c++/join-two-linked-list.cpp ) |
218
221
| Delete tail of circular linked list| [ C++] ( c++/delete-tail-of-circular-linked-list.cpp ) |
Original file line number Diff line number Diff line change
1
+ // https://practice.geeksforgeeks.org/problems/count-only-repeated/0/?track=SPCF-Searching&batchId=154
2
+ /*
3
+ Given an array of positive integers, where elements are consecutive (sorted).
4
+ Also, there is a single element which is repeating X (any variable) number of times. Now, the task is to find the
5
+ element which is repeated and number of times it is repeated.
6
+ */
7
+
8
+ #include < iostream>
9
+ using namespace std ;
10
+
11
+ void solve_test ()
12
+ {
13
+ int size_list;
14
+ cin >> size_list;
15
+ int arr[size_list];
16
+ for (int i =0 ; i < size_list; i++)
17
+ {
18
+ cin >> arr[i];
19
+ }
20
+
21
+ int counter = 0 ;
22
+ int element;
23
+ for (int i =0 ; i < size_list-1 ; i++)
24
+ {
25
+ if (arr[i] == arr[i+1 ])
26
+ element = arr[i];
27
+ while (arr[i] == arr[i+1 ])
28
+ {
29
+ counter +=1 ;
30
+ i+= 1 ;
31
+ }
32
+ }
33
+ counter+=1 ;
34
+ cout << element << " " <<counter<<endl;
35
+ }
36
+
37
+ int main ()
38
+ {
39
+ ios_base::sync_with_stdio (false );
40
+ cin.tie (NULL );
41
+
42
+ long int t;
43
+ cin >> t;
44
+ while (t--)
45
+ solve_test ();
46
+ return 0 ;
47
+ }
You can’t perform that action at this time.
0 commit comments