The constraint for n is 1<=n<=10^5 but we had to take long long for storing the count value of 1’s
but count value of 1’s must be less than or equal to 10^5.
Can someone explain me why???
You don’t have to, but it makes it easier to avoid overflow when computing (num1s * (num1s - 1))/2. You could also do e.g.:
#include <iostream>
using namespace std;
int main()
{
int T;
cin >> T;
for (int t = 0; t < T; t++)
{
int n;
cin >> n;
string binaryString;
cin >> binaryString;
int num1s = 0;
for (const auto bit : binaryString)
{
if (bit == '1')
num1s++;
}
cout << (static_cast<long long int>(num1s) * (num1s - 1)) / 2 << endl;
}
}
Quite often Competitive Programmers will use long long int or an equivalent instead of int for all variables as it can be less error-prone.
Can some check what is the error in my code, i used something like two pointer to count starting 1 and added all the ending 1’s after that pointer https://www.codechef.com/viewsolution/38096948
in this case
why NOT 101 or 1001 or 11 like cases been takes .
they have said for substring and we can pair them in any orders.
BUT WHY we have to choose indices first and pair. Can SOmeone TELL?