Better code then this

please check my code https://ide.codingblocks.com/s/163259

please suggest me the better way to solve this question

also what among subset, subsarray, substring which must be continueous

Hello @pankajsingh,

  1. The way you have solved the problem is itself a good way of solving this question.
    If you want another approach then you can go through the following code:
    https://ide.codingblocks.com/s/163284

  2. Sub-array and sub-strings are continuous while subset can be non- continuous also.

Hope, this would help.
Give a like if you are satisfied.

sir in compare function what this return a<b

sir in compare function what this return a<b mean. i am also not able to understand this in the video. and sir in your code what is this true or false signify ,i haven’t seen this in the video, in video lecture we have done only return as return (a<b)/ or return a>b;

Hello @pankajsingh,

  1. This is the code that I have written before watching the video.

  2. You have seen writing return (a<b)/ or return a>b;
    Did you ever bother what are they actually doing?
    What are they returning?
    What is its significance?

    Let’s understand this with an example:

    suppose you have to sort an array in increasing order.
    Your mycompare() function is accepting two parameters a and b.
    and you have written return a<b;
    then the statement would return true if a is smaller than b.
    So, sort() function will place a before b.
    and in case of false.(when a is greater than b)
    The sort() function would place b before a.

    Same is the case for decreasing order.

    Hence, concluding:
    true indicates that a should be placed before b in the sorted order.
    and false indicates that a should be placed after b in the sorted order.

  3. Now understand the mycompare() function:
    int i=0;
    //Comparing both strings character by character for equality from left to right:
    //increment the index i
    while(a[i]==b[i]) i++;
    //if a is prefix of b
    //Then string b should be placed before a
    if(a[i]==’\0’) return false;
    //if b is prefix of a
    //then a should be placed before b
    else if(b[i]==’\0’) return true;
    //if neither of a and b are frefix of each other
    //Compare lexicographically
    //if a is smaller, return true i.e. a should be placed before b
    // else, return false i.e. b should be placed before a
    return a < b;

Hope, this would help.
Give a like if you are satisfied.

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.