I am not oassing two test cases

https://www.geeksforgeeks.org/find-the-smallest-window-in-a-string-containing-all-characters-of-another-string/ You can have a look at this code for reference.

i have also implemented this same logic
please give it a look

i have submitted your code on gfg and it is giving me correct answer.
you can check yourself

code:

#include<iostream>
#include<climits>
#include<string>
using namespace std;
string pattern(string s, string p)
{
  int sl = s.length();
  int pl = p.length();
  if (pl > sl)
  {
    return "-1";
  }

  int fs[256] = {0};
  int fp[256] = {0};
  for (int i = 0; i < pl; i++)
  {
    char ch = p[i];
    fp[ch]++;
  }
  int count = 0;
  int start = 0;
  int min_size = INT_MAX;
  int start_idx = -1;
  for (int i = 0; i < sl; i++)
  {
    char ch = s[i];
    fs[ch]++;
    if (fp[ch] != 0 && fs[ch] <= fp[ch])
    {
      count++;
    }
    if (count == pl)
    {
      char temp = s[start];
      while (fp[temp] == 0 || fs[temp] > fp[temp])
      {
        fs[temp]--;
        start++;
        temp = s[start];
      }
      int window_size = i - start + 1;
      if (window_size < min_size)
      {
        min_size = window_size;
        start_idx = start;
      }
    }
  }
  if (start_idx == -1)
  {
    return "-1";
  }
  string ans = s.substr(start_idx, min_size);
  return ans;
}
int main()
{


  int tc = 1;
  int t; cin >> t; while (t--)
  {
    string s;
    string p;
    // getline(cin, s);
    cin >> s;
    cin >> p;
    // cout << s << "----" << endl;
    // getline(cin, p);
    cout << pattern(s, p) << endl;
    tc++;
  }
}

maybe some internal error, or you are messing up with getline.

Thanks.

there is no error in getline function

only two test cases are failing out of 10

Then there must be some internal error because your code is passing all test case on gfg. I will inform the team about this

hey @Vipul.kapoor you are returning wrong string in base cases . I have updated your code . see it below

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.