We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

Brute force approach will not be sufficient to solve this problem.because time complexity of brute force algorithm is O(n * m) which is very high, for given time constraint, so you need better approach which beats O(nm).

If interested to know why your solution did not work out.

## Array Manipulation

You are viewing a single comment's thread. Return to all comments →

Hello friends,

Brute force approach will not be sufficient to solve this problem.because time complexity of brute force algorithm is O(n * m) which is very high, for given time constraint, so you need better approach which beats O(nm).

If interested to know why your solution did not work out.

click here for the

video explanation of generic algorithmwith complexity analysis.or you can click on the image too to follow youtube tutorial.

Here is the working solution with O(n+m) complexity:-source code :Would really appreciate your feedback like, dislike , comment etc. on my video.

## Do not forget to upvote, if you find it useful.