I am unable to understand what is wrong with this solution : CodeChef: Practical coding for everyone
When i run this program it shows : Exception in thread āmainā java.lang.StringIndexOutOfBoundsException: String index out of range: 7
at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:44)
at java.base/java.lang.String.charAt(String.java:692)
at numberOfOpenTweets.main(numberOfOpenTweets.java:16)
So if you can spot the error please tell
Memset would also take O(N) time to go through each element. But yes, the actual time might be lesser.
For every CLOSEALL, we do not do anything if number of tweets is 0. That could help but doesnāt lower worst case time.
I used memset for filling 0s. My solution was showing wrong answer though I have implemented it same as mentioned in the tutorial.
http://www.codechef.com/viewsolution/1132512
Canāt find what is the difference ![]()
@vikram535 : Please check the āmemsetā function in the library. The last parameter should be the number of bytes, and not number of elements in the array. If your array is int A[1001]; , you should use it as, memset(A,0,sizeof(A));
You meant for example O(1/2 * N)? In fact that doesnāt matter, itās asymptotically O(N).
Thank you so much for pointing out my mistake. I was not able to find it. Thanks again 
hey thnxā¦my mistake i didnāt observe datā¦thnx a lotā¦
Your class cannot be public, thatās the first problem at CodeChef. In addition
int c = Integer.parseInt(t1.substring(n - 1, n));
c = c - 1;
You forgot to print number of open tweets after input āCLOSEALLā
I have added print statement and hereās the accepted version of your code
Thanks a lot!! 
most welcome 
I did it in a similar way and the answer is submitted
#include
#include
#include
#include
using namespace std;
int main ()
{ ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,k;
cin>>n>>k;
std::string str;
std::bitset<1000> boo;
while(kā){
cin>>str;
if(str ==āCLOSEALLā){
boo.reset();
cout<<0<<"\n";
}
else{
int c;
cin>>c;
boo = boo.flip(1000-c);
cout<<boo.count();
cout<<endl;
}
}
return 0;
}
Can anyone help me out here? Iām getting wrong answer status. Whatās wrong in my code?
https://www.codechef.com/viewsolution/25035176
you didnāt consider elements bigger than 9
your code will fail on those test cases
Thank you for pointing it out. It was kind of a silly mistake. Hereās the correct one.
https://www.codechef.com/viewsolution/25048355
This code is giving NZEC error Please help me 
class TWTCLOSE {
int result = 0;
static int Program(String str, int val, int[] arr) {
if (arr[val] == 0) {
arr[val] = 1;
result++;
} else {
arr[val] = 0;
result--;
}
return result;
}
public static void main(String[] args) throws IOException {
java.io.BufferedReader r = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
int n = 0;
int k = 0;
n = r.read();
r.readLine();
k = r.read();
r.readLine();
int[] arr = new int[Character.getNumericValue(n)];
k = Character.getNumericValue(k);
if (n >= 1 && k <= 1000) {
while (k > 0) {
String str = r.readLine();
int length = str.length();
str.trim();
if (str.equalsIgnoreCase("closeAll")) {
System.out.println("0");
Arrays.fill(arr, 0);
result = 0;
} else {
int val = Integer.parseInt((str.substring(length - 1, length)));
System.out.println(Program(str, val-1, arr));
}
k--;
}
}
}
}
This is how I did it in Java.
class Codechef {
public static void main (String[]args) throws java.lang.Exception
{
// your code goes here
Scanner in = new Scanner(System.in);
int n=in.nextInt();
int k = in.nextInt();
in.nextLine();
int ans=0;
int[] a = new int[n];
for (int i=0;i<k;i++)
{
String s=in.nextLine();
if (s.charAt(2)=='O')
{
ans=0;
a = new int[n];
}
else
{
int l=s.length();
String numstr=s.substring(6);
int num=Integer.parseInt(numstr);
if (a[num-1]==0)
{
a[num-1]=1;
ans++;
}
else
{
a[num-1]=0;
ans--;
}
}
System.out.println(ans);
}
}
}
x,t = map(int,input().split())
st=""
while(t):
s = input()
if(āALLā in s):
st=""
else:
for i in range(1,x+1):
if(str(i) in s):
if(str(i) in st):
st = st.replace(str(i),"",1)
else:
st+=str(i)
# print(st)
print(len(st))
t-=1
what is wrong in this pls help me