Open In App

Contest Experience: Leetcode Weekly Contest 344 (7th May)

ABOUT THE CONTEST: This contest was organized by Leetcode on May 7th, it consisted of 4 questions and the time given to solve them was 1 hour 30 minutes.

WINNING PRIZES:



Rank

Prize

1st

Apple HomePod mini

2nd

Logitech G903 LIGHTSPEED Gaming Mouse

3rd-5th

Backpack

6th-20th

Water bottle and Notebooks

LINK OF THE CONTEST: 344th LeetCode Weekly Contest

OVERVIEW OF THE QUESTIONS:



Problem Name

Difficulty

Pre-requisite

Approx time to solve by me

number of submissions by me

Find the Distinct Difference Array

Easy (3 points)

Array and Sets

3-4 minutes

1

Frequency Tracker

Medium (4 points)

Hashing and multisets

5 minutes

1

Number of Adjacent Elements With the Same Color

Medium (5 points)

Basic Observations

7-8 minutes

1

Make Costs of Paths Equal in a Binary Tree

Medium (5 points)

Perfect Binary Trees and Recursion

50 – 60 minutes

2 (1 WA)

LET’S DISCUSS:

Problem 1: Find the Distinct Difference Array
My Experience: As usual, the first question was quite easy, the problem statement was straightforward and it took me around 4 minutes to type the solution, for someone with fast typing speed this question could have been solved within a minute or two.
Accepted Solution: We could simply just create two different arrays to store the number of unique elements on the left and right sides of each index and return the difference for each index. This would give us a complexity of O(N).

Problem 2: Frequency Tracker
My Experience: This was a design problem in which we have to implement 3 functions, it was my first time seeing a design problem in a contest and it took me around 5 minutes to solve this question.
Accepted Solution: For storing different frequencies we could use a multiset and update them using a hash map. Each function will work in O(log N) complexity.

Problem 3: Number of Adjacent Elements with the Same Color.
My Experience: This question is a standard problem and I guess I have already solved this question on some other platform, but this was a good question and I was able to solve it in around 8 minutes.
Accepted Solution: To solve this problem, we can initialize our answer as 0, after each query we will just subtract the count of equal adjacent numbers before updating the index and add the count of equal adjacent numbers after updating the index. This can be done in O(1) for each query.

Problem 4: Make costs of Paths Equal in Binary Tree.
My Experience: 1 silly mistake and I had to debug this question for 40 minutes. Usually, 4th question is Hard and I am not able to solve it during the contest but this time it was a medium-level question and I took around 50 minutes to solve this one.
Reason for WA: During the recursion call, I updated the cost array to the sum of its child nodes which was wrong. Actually, it had to be updated to the max of its child nodes.
Accepted Solution: We can calculate the minimum cost by traversing the tree from bottom to top using recursion very easily, Just add the absolute difference of the child nodes to our answer and add the maximum of both child nodes to the parent nodes.

CONCLUSION: Usually I am able to solve 3/4 questions but this time I was able to solve all 4 of those problems as this contest was on the easier side of the spectrum. Took me around 1 hour and 10 minutes to solve this contest.

Article Tags :