Skip to content

Commit

Permalink
Added new question in Array section
Browse files Browse the repository at this point in the history
  • Loading branch information
KaranSiddhu committed Apr 28, 2022
1 parent 51fa245 commit 057f4be
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define ld long double
#define el "\n"

//Time Complexity: O(N)
void solution(){
int n = 6;
int a[n] = {10, 10, 10, 25, 30, 30};

int ans = 1;
for (int i = 1; i < n; i++){
if(a[i] == a[i-1]){
ans++;
}else{
cout << a[i-1] << " - " << ans << el;
ans = 1;
}
}
cout << a[n-1] << " - " << ans << el;
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);

int t;
cin >> t;
while (t--)
solution();

return 0;
}

0 comments on commit 057f4be

Please sign in to comment.