Can we have the input of array size because I can’t see such thing in example problems, If Yes whats wrong with this code :
—> Link to Question : Contest Page | CodeChef
using namespace std;
//cout<<“Enter testacase Number\n”;
// cout<<"Enter No of elements\n";
No your approach is not correct.we have to find such number in array(i prefer arraylist) which itself is equal to the no of total elements(except itself),then we have discard number iteself from array and sort remaining array and find the max.But may be there is more efficient algorithm than this
Just try this on paper, You will get the right answer.
I dont think we need to remove something. Just check this out on paper.
n is not given in input, that was the trick of this problem. You need to take entire line as input becayse we dont know value of n.
If n is given then yup… your logic is correct. But n is not given here… so you have to find n by taking whole line as input, as @vijju123 said.
i means if we remove n from arraylist then sort the remaining elements and after that we can find max.
n is not given thats you have to find n first,read my algorithm again.