Problem had weak test cases I think so
https://www.codechef.com/viewsolution/30671225
Fails the following test case:
1
4
2 1 1 2
Expected op:
1
Actual op:
0
Yet the problem was given AC
Problem had weak test cases I think so
https://www.codechef.com/viewsolution/30671225
Fails the following test case:
1
4
2 1 1 2
Expected op:
1
Actual op:
0
Yet the problem was given AC
Exactly
@rajatrc1705 my program is giving output 1 on your given test case but actual ans is 0 so my submission got WA what to do for this?any one help
SOLVED
How can i create circular array and count the number of elements that lies between two maximum elements?
if is very confusing
for example
elements- 1 2 2 1 2 1
index-------0 1 2 3 4 5
max element=2
between index 1 and 2
between index 2 and 4
between index 4 and 1(4,5,0,1)
if i use circular linked list it will become complicated.
The correct answer is 1.
https://www.codechef.com/viewsolution/30674585
In the following code segment, why is the commented if accessed even when the condition is failing. Getting WA due to that reason!!
Solution-https://www.codechef.com/viewsolution/30670670
I am not able to figure why i am getting WA in this?
Please someone help whats the problem or you can give test cases too!
Thanks!!
you can refer my solution ,if any doubts u can ask me
#include <bits/stdc++.h> # define ll int using namespace std; int main() { ll t; cin>>t; while(t--) { ll n,i,j,k; cin>>n; ll a[n],mx=0,c[n]={0}; for(i=0;i<n;i++) { cin>>a[i]; mx=max(mx,a[i]); } for(i=0;i<n;i++) { if(a[i]==mx) c[i]=1; } ll x=0,y=0,f=0,ans=0; for(i=0;i<n;i++) { if(f==0) { if(c[i]==0) x++; } if(f==1) { if(c[i]==0) y++; } if(i==n-1 && c[i]==0) { ans+=max(((x+y)-(n/2)+1),0); } if(c[i]==1) { f=1; if(y!=0) ans+=max((y-(n/2)+1),0); y=0; } } cout<<ans<<"\n"; } return 0; }
Explain me this @tmwilliamlin
for _ in range(int(input())):
n=int(input())
l=list(map(int,input().split()))
x=l.index(max(l))
y=n-l[::-1].index(max(l))-1
if y-x > n//2:
print(0)
else:
print(n//2-(y-x))
why this works (solution of other person) , he considers only first and last index of max value. ?
I feel the solution here is so overkill 
Can’t we just use a hash map and store the count of elements and as we move, remove the element a[n/2-1], a[n/2-2],… and add a[n-1], a[n-2]… and keep continuing like that. And after each check if the hash[max] is zero or not.
Here, the Max element will be 1. Also, like it is said in the editorial, the difference or gap between any two maximums will be 0, thus the answer will be 0.
Also, if you think about it, the chef wants to avoid the sweet with maximum sweetness, and here all the sweets have max sweetness, so the answer is fairly evident.
Yes it will work as he is considering the smallest and the greatest index of max element and there can be only one or none valid subarray, if there is a valid subarray then such valid subarray is only one ,other subarray will not be valid as it results in l<n/2.
So valid subarray will have l==n/2 or l>n/2 and in this case the answer is l-(n/2)+1
Unnecessary wasting precious data structures
This problem has weak test cases.Take for instance-
1
14
2 1 1 1 1 1 1 1 2 1 1 1 2 1
Tester’s Solution gives the correct answer =1 but CodeChef: Practical coding for everyone gives answer=0. I think the @raja1999 should look into this matter.
I am getting a time limit exceeded on my code. Can someone please see it and tell me how I can optimize it? CodeChef: Practical coding for everyone
Edit: I have also tried using “reserve” keyword on the vector to allocate storage at once. But I am still getting the time limit exceeded error. CodeChef: Practical coding for everyone
if someone knows these precious ds and can implement the problem using it in only 5 to 7 minutes , then i think its not a wastage 