Exist or not wrong output

sir I tried this exist or not using hashing but it is giving wrong answer .can u plzz tell me that the concept which I am thinking is correct??
link:https://ide.codingblocks.com/s/122894

Hello @khushi91200,

You have skipped one of most important part in your code i.e. Taking input.

  1. The first line of input contains the number of test cases T.
  2. The first line of each case contains an integer L denoting the length of the array. i.e. the value of n in your code.

Modify your code as specified above and it will pass all the test cases.

Extra information: (You can try this also)

The map::find() is a built-in function in C++ STL which returns an iterator or a constant iterator that refers to the position where the key is present in the map. If the key is not present in the map container, it returns an iterator or a constant iterator which refers to map.end().

Worst time complexity is O(n) i.e. same as that of the code you have written.
Now, think how can you use this in your code.

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

one test case is passed and other test case is showing time limit exceeded link:https://ide.codingblocks.com/s/122908

Hello @S18ML0016,

I have checked the test cases.
In the second test case, the value of q is negative.

Do the following modification, and your code will work perfectly:
while((q–) > 0){}

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

sir I didn’t understood you where to implement this in code plzz help!!

Sure,

You can see the following code:

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

2 Likes