DEV Community

Karthika Movva
Karthika Movva

Posted on

This week experience

Hi, Folks! I have been solving the LeetCode questions daily and have noticed small improvements in myself. This encourages me to continue this problem solving. Understanding and visualizing data structures will become better day by day. Concepts like recursion and backtracking need number of problems to grasp.

On the First day, I started with some simple problems like reverse linked list this involves interchanging of links between nodes. The ‘Add two numbers’ problem was solved with help of dummy node concept. For ‘Merge k sorted lists’, we can use heaps to pop the smallest possible element, this makes sorting process easier.

On the Second day, I focused on some linked list types. In ‘Linked list cycle’ problem, we return true if the given input is circular linked list or else we return false. We can use Hare and Tortoise Algorithm to solve this problem. For ‘Palindrome linked list’ problem we divide the given linked list into two equal parts and reverse the second half of the linked list. Then, we compare the nodes of first half with those of second half. If they are same through out the linked list, it is a palindrome.

On the Third day, I covered the concept of queue and stacks. “Implement the queue using stack” is a conceptual question. For “Sliding window maximum” to solve this problem, we can use dequeue to store the indices of maximum elements every time the window slide. For “Perfect square”, we can use dynamic programming to store the minimum number of perfect squares required to add up to give input.

On the Fourth day, I covered some recursion and backtracking involved problems. For “Spiral matrix”, we use index limits and for loops to print elements in spiral order. For “N-Queens” to solve this problem we have three lists upper diagonal, lower diagonal and row. If I place a queen in any position, I update the corresponding position in list to indicate that already queen exists and helps to avoid unnecessary recursion. For “Unique paths”, we observe that every cell has two possible ways to be reached, we can use this logic to solve the problem.

I hope my experience will be helpful!

Top comments (0)