April Long - Behind the scenes

This:

    char str[k];
        
        //for(int i=0; i<k ;i++)
        //str.push_back('*');
    memset(str,'*',k);
    	str[k]='\0';

is an out-of-bounds access and hence Undefined Behaviour:

[simon@simon-laptop][21:49:14]
[~/devel/hackerrank/otherpeoples]>./compile-latest-cpp.sh    
Compiling akshay_012-SSCRIPT.cpp
+ g++ -std=c++14 akshay_012-SSCRIPT.cpp -O3 -g3 -Wall -Wextra -Wconversion -DONLINE_JUDGE -D_GLIBCXX_DEBUG -fsanitize=undefined -ftrapv
akshay_012-SSCRIPT.cpp: In function ‘void KMPSearch(char*, char*)’:
akshay_012-SSCRIPT.cpp:16:16: warning: conversion to ‘int’ from ‘size_t {aka long unsigned int}’ may alter its value [-Wconversion]
  int M = strlen(pat);
          ~~~~~~^~~~~
akshay_012-SSCRIPT.cpp:17:16: warning: conversion to ‘int’ from ‘size_t {aka long unsigned int}’ may alter its value [-Wconversion]
  int N = strlen(txt);
          ~~~~~~^~~~~
+ set +x
Successful
[simon@simon-laptop][21:49:20]
[~/devel/hackerrank/otherpeoples]>echo "3
5 2
*a*b*
5 2
*a**b
5 1
abcde" | ./a.out
akshay_012-SSCRIPT.cpp:110:11: runtime error: index 2 out of bounds for type 'char [*]'
NO
YES
NO

can debug this please CodeChef: Practical coding for everyone
by putting str[k]=‘\0’ before memset (it did not give out of bound )
also it get ac why .?

There’s Undefined Behaviour for you :man_shrugging:

1 Like

What’s wrong in my solution in question worthy matrix?
Solution link:- CodeChef: Practical coding for everyone
I have used prefix sum matrix
Then do binary search where square matrix solutions exist…

Can anybody tell me that in worthy matrix problem why three inner for loop solution work I mean in that type of solution time complexity is O(N^3)…

@alei Can you please disclose the variants of Tree Permutation TREEPERM problem you suggested other than the counting one which were hard.

@prash_pra2 Who knows, maybe they will, maybe you will get link for interview and thats it for you. You wont pass the interview cause you don’t really know anything except for searching solutions on youtube.

Ok @prash_pra2 , i reported you.

You cant just call someone cheater coz you feel like so

Why edit your reply. I don’t think you know that others can look onto your submissions and i don’t think you know anything about MOSS either. You just log onto codechef, copy paste answer and call it a day.

People like you disgusts me.

4 Likes

Nice fight going on down there … Have a lookk :wink: