Answer the question
In order to leave comments, you need to log in
What is the correct way to get a negative result of a substring?
Good evening!
Recently, I encountered the fact that after the second test of my solution to a problem in PHP, I did not receive the required result that I should have done it in accordance with the conditions for solving the problem.
The essence of the problem is this and what are the conditions for its solution:
The first test passed successfully in accordance with the conditions of the solution, and the second test brought bad surprises, giving various compiler messages:
PHP Notice: String offset cast occurred in <код решения> on line 45
PHP Notice: String offset cast occurred in <код решения> on line 46
Answer the question
In order to leave comments, you need to log in
In addition to the obvious problems, you have an invalid palindromic check.
Your code, for example, will consider the string "aab" as a palindrome.
Then, for some reason, the binpoisk is added here. Why is not at all clear.
Also, your solution is too slow. Here the complexity is of the order of O(n^2 log n), which for 200000 will not fit into any restrictions.
For the correct solution, only one observation is needed - for any palindrome, you can take the middle of length 2 or 3 - this will be a shorter palindrome. Therefore, if there are at least some palindromes in the string, then there are definitely palindromes of length 2 or 3.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question