DEV Community

Mukilan Palanichamy
Mukilan Palanichamy

Posted on

My journey in Competitive Programming

Hi, folks! Today, I solved three problems on LeetCode: "Find All Anagrams in a String," "Longest Consecutive Sequence," and "Search in Rotated Sorted Array." These problems are very interesting, and we have different logical approaches to solve them. They are the extension of the classic problems checking whether two strings are anagrams or finding a target element in an array.

Find All Anagrams in a String:

We can solve this problem using the sliding window technique. We have to pass through the input array, keeping track of a fixed-length consecutive elements. We check whether this segment is an anagram of the target string. If it is, we add the index to the result array; if not, we ignore the index. In this way we can solve the problem.

Longest Consecutive Sequence:

We will first remove the duplicate elements from the array using a set. Then, we will iterate over the array and check for any sequence of consecutive elements (+1 or -1). If such a sequence exists, we keep track of its count; otherwise, we ignore it. This way, we can find the length of the longest consecutive sequence.

Search in Rotated Sorted Array:

We can use the approach of binary search to solve this problem. We split the input array into two halves. Then we find out which half is sorted and perform a binary search in that half for the target element. If it does not find the target in the sorted half, it continues its search in the unsorted half. If the target element is not found in either half, we return -1. In this way we can solve this problem.

I hope my experience is helpful.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay