I have submitted the “String Window” challenge and i passed all test cases except textcase 8 which says “run-error”, i have downloaded the testcase and when i run it on my intellij compiler it works fine and the output matches the accepted output. Please look into this problem.
Problem in codingblocks java compiler
Hey Parikshit,
Can you share the link to your code.
import java.util.*;
public class Minsubstringprint{
static final int no_of_chars = 256;
static String findSubString(String str, String pat)
{
int len1 = str.length();
int len2 = pat.length();
if (len1 < len2)
{
return "No string";
}
int hash_pat[] = new int[no_of_chars];
int hash_str[] = new int[no_of_chars];
for (int i = 0; i < len2; i++)
hash_pat[pat.charAt(i)]++;
int start = 0, start_index = -1, min_len = Integer.MAX_VALUE;
int count = 0;
for (int j = 0; j < len1 ; j++)
{
hash_str[str.charAt(j)]++;
if (hash_pat[str.charAt(j)] != 0 &&
hash_str[str.charAt(j)] <= hash_pat[str.charAt(j)] )
count++;
if (count == len2)
{
while ( hash_str[str.charAt(start)] > hash_pat[str.charAt(start)]
|| hash_pat[str.charAt(start)] == 0)
{
if (hash_str[str.charAt(start)] > hash_pat[str.charAt(start)])
hash_str[str.charAt(start)]--;
start++;
}
int len_window = j - start + 1;
if (min_len > len_window)
{
min_len = len_window;
start_index = start;
}
}
}
if (start_index == -1)
{
return "No string";
}
return str.substring(start_index, start_index + min_len);
}
public static void main(String[] args)
{
Scanner scan=new Scanner(System.in).useDelimiter("\n");
String str;
str=scan.next();
String pat = scan.next();
System.out.println(findSubString(str, pat));
}
}
Hi
@sanjeetboora Please let me know the status of doubt.
Is there any issue in test cases or something else?
It has been 4 days since i asked this doubt and it has not been resolved yet, please look into this matter.
Hi
@bobby667788 I have seen the approach of your code, it is correct, i don’t see any error in your approach, i think may be some issue in test case number 8.
@sanjeetboora Please do check the test cases.
Hi Parikshit,
I am really sorry for the late reply. Please try to submit your code again.
Yes i have marked it as resolved