https://hack.codingblocks.com/contests/c/474/211
MY CODE IS :
https://ide.codingblocks.com/#/s/14033
HIDDEN TEST CASES NOT PASSING. EVEN THOUGH GIVING CORRECT OUTPUT ON CODEBLOCKS IDE
https://hack.codingblocks.com/contests/c/474/211
MY CODE IS :
https://ide.codingblocks.com/#/s/14033
HIDDEN TEST CASES NOT PASSING. EVEN THOUGH GIVING CORRECT OUTPUT ON CODEBLOCKS IDE
Actually, the problem is in your sorting algorithm. It has been implemented poorly.
Instead of writing the code for bubble sort, just use the built-in sort() function :
#include <algorithm> // for sort()
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
for(int i=0; i<n; ++i) cin >> arr[i];
sort(arr, arr+n); // sorts from index 0 to n-1
/*
Rest of your code goes here
*/
}
I understand sir. But what was poor in my algorithm sir? Pls tell me so i can improve later on
I’ll give you a test case and let you figure it out :
3
1
2
3
3
Actually, you’re using 1-based indexing for sorting and the rest part of the program uses 0-based array indexing. Change it and you’ll get the correct ans. If you still face any problem, refer this code