Getting syntax errors

I believe my logic is correct. But I’m getting some syntax errors. Please help me with my issue ASAP.

@mohammadabdullahjawwad in line 45
image

  1. syntax for reverse() is wrong, if you want to reverse the string s, it should be like reverse(s.begin(), s.begin() + j)
  2. reverse() function makes changes in the container itself, and it does not return anything.So you cannot use a void value as an argument for the find() function

Dont forget to mark your doubt as resolved :slight_smile:

Still getting a bunch of errors! Please help

@mohammadabdullahjawwad i already told you, reverse() does not return anything. You cannot use it inside find function because it will return void.

So what should I do instead? What is the way forward

@mohammadabdullahjawwad reverse the string in a separate line and use the substring function for the argument of find function. You can reverse the string back after that line again, if you dont want the original string to reflect any changes.

Made the said change. Still not working

@mohammadabdullahjawwad use the substr function, you cannot make a substring like this. Please read the documentations of these functions once to gain some clarity as you dont seem familiar with operations on strings.

Just one last step left, I want to convert the value returned by the iterator (to the unordered_set) to int. How can I achieve it. Also, if you have any additional comments please do.

@mohammadabdullahjawwad i am assuming you wish to extract the index, so if it returns the iterator itr for example, and set name is s, you can do
itr-s.begin()

Please mark your doubt as resolved if all your queries are solved :slight_smile:

Still getting errors! I’d be grateful if you could make the desired changes in the code in order to remove the errors. If, in any case, you’re not understanding my logic (which I highly doubt) then I can explain it to you. :frowning:

@mohammadabdullahjawwad sorry my bad, it will not work in unordered_set because it does not have contigous memory. I guess you can iterate over the length of the set and check if the iterator matches, cannot think of any other way right now

I had thought of this, but this will further increase the time complexity by O(n). And will consequently lead to TLE, since the overall complexity will become O(n^2 * length of string).

hi @mohammadabdullahjawwad i will look for a way, meanwhile I’d recommend you to raise a separate doubt regarding this so that someone else can also help :slight_smile:

Sure, thanks a lot @Ishitagambhir ! As soon as you get a solution, please let me know (if possible). My email is [email protected]. Thanks again :slight_smile:

1 Like

@mohammadabdullahjawwad sure

@mohammadabdullahjawwad your index retreival is incorrect!
use unordered_map to store the indexes.
also use return type as vector<pair<int,int>> as you push using make_pair.

Im having problem in implementation of unordered_map

We use count to know whether a particular entry exists inside hashmap.


works now, it had some issues with pointers (j instead of j+1)

Please explain to me why we took j+1 instead of j. Also in leetcode, we have to submit as vector < vector < int > > and not vector<pair<int, int>> hence I had used it :sweat_smile: