Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define debug(n) cout<<(n)<<endl;
const ll INF = 2e18 + 99;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--){
int n;
cin>>n;
string s, k;
cin>>s;
k = s;
sort(s.begin(), s.end());
int arr[n];
int m = 0;
for(int i = 0; i < s.length(); i++){
if(k[i] != s[i]){
arr[m] = i+1;
m++;
}
}
if(m != 0){
cout<<1<<endl;
}
cout<<m<<" ";
for(int i = 0; i < m; i++){
cout<<arr[i]<<" ";
}
cout<<endl;
}
}
Copy The Code &
Try With Live Editor
Input
3
7
0011111
5
10100
6
001000
7
0011111
5
10100
6
001000
Output
0
1
4 1 3 4 5
1
3 3 5 6
1
4 1 3 4 5
1
3 3 5 6
Demonstration
Codeforcess Solution 1605-B B. Reverse Sort ,C++, Java, Js and Python ,1605-B,Codeforcess Solution