Sort 0 1
Sort 0 1
Send Feedback
Sort 0 1
You need to change in the given array/list itself. Hence, no need to return or print anything.
The first line contains an Integer 't' which denotes the number of test cases or queries to be run. Then the test cases follow.
First line of each test case or query contains an integer 'N' representing the size of the array/list.
Second line contains 'N' single space separated integers(all 0s and 1s) representing the elements in the array/list.
For each test case, print the sorted array/list elements in a row separated by a single space.
Output for every test case will be printed in a separate line.
1 <= t <= 10^2
0 <= N <= 10^5
Time Limit: 1 sec
1
7
0 1 1 0 1 0 1
0 0 0 1 1 1 1
2
8
1 0 1 1 0 1 0 1
5
0 1 0 1 0
0 0 0 1 1 1 1 1
0 0 0 1 1
#include <iostream>using namespace std;
int tripletSum(int *input, int size, int x){ //Write your code here int count=0; for(int i=0;i<size;i++){ for(int j=i+1;j<size;j++){ for(int k=j+1;k<size;k++){ if(input[i]+input[j]+input[k]==x){ count++; } } } } return count;}
int main(){ int t; cin >> t;
while (t--) { int size; int x; cin >> size;
int *input = new int[size];
for (int i = 0; i < size; i++) { cin >> input[i]; } cin >> x;
cout << tripletSum(input, size, x) << endl;
delete[] input; }
return 0;}
Comments
Post a Comment