Sir, for this question, I used a naive approach. But, on submitting, I'm getting wrong answer on test 2. I have invested 3 hours (after the contest) on my existing approach before viewing this video solution. I request you to please reply me regarding WHY this approach isn't getting passed ? My code is : #include using namespace std; void printVec(vector vec){ for(int i = 0; i < vec.size(); i++){ cout > k; vector vec; for(int i = 0; i < n; i++){ vec.push_back(i + 1); } // Edge Cases if(k == n - 1){ printVec(vec); return; } if(k == 0){ reverse(vec.begin(), vec.end()); printVec(vec); return; } int i = 0, j = 1; int count = n - 1; while(count != k && i < n && j < n){ swap(vec[i], vec[j]); count--; i += 2; j += 2; } if(count == k){ printVec(vec); return; } } int main() { int t; cin >> t; for (int i = 0; i < t; i++) { solve(); } return 0; }
can you show how it would be done in python?
Sir, for this question, I used a naive approach. But, on submitting, I'm getting wrong answer on test 2.
I have invested 3 hours (after the contest) on my existing approach before viewing this video solution.
I request you to please reply me regarding WHY this approach isn't getting passed ?
My code is :
#include
using namespace std;
void printVec(vector vec){
for(int i = 0; i < vec.size(); i++){
cout > k;
vector vec;
for(int i = 0; i < n; i++){
vec.push_back(i + 1);
}
// Edge Cases
if(k == n - 1){
printVec(vec);
return;
}
if(k == 0){
reverse(vec.begin(), vec.end());
printVec(vec);
return;
}
int i = 0, j = 1;
int count = n - 1;
while(count != k && i < n && j < n){
swap(vec[i], vec[j]);
count--;
i += 2;
j += 2;
}
if(count == k){
printVec(vec);
return;
}
}
int main() {
int t;
cin >> t;
for (int i = 0; i < t; i++) {
solve();
}
return 0;
}
What is the answer for your solution for test case
1
5 1
i.e. n = 5 and k = 1, it returns empty. This is one issue.
haa sir yeh galti thi. Thanks for pointing it out.