Open In App

Contest Experience: LeetCode Weekly Contest 361

Last Updated : 29 Sep, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

ABOUT THE CONTEST: LEETCODE #WEEKLY CONTEST 361

This weakly contest was organized by Leetcode on 3 Sep 2023. In this contest, there is a total of 4 problem statements and you need to solve this question in a given time slot. 90 minutes are provided to solve these questions. The ranking was based on the following:

  • Maximum score.
  • Minimum time required to solve these questions.
  • penalty time of 5 minutes for each wrong submission.

Bonus Prizes

  1. 1st Rank: Apple HomePod mini
  2. 2nd Rank : Logitech G903 LIGHTSPEED Gaming Mouse
  3. 3rd to 5th Rank: LeetCode Backpack
  4. 6th to 10th Rank: LeetCode water bottle
  5. 11th to 20th Rankis taken: LeetCode Big O Notebook

Link of the Contest: https://leetcode.com/contest/weekly-contest-361/

OVERVIEW OF ALL CONTEST QUESTIONS:

Question Name

Difficulty

Total score

Approx. time is taken by me

Number of Submissions by me

Count Symmetric Integers

Easy

3

8

1

Minimum Operations to Make a Special Number

Medium

4

10

1

Count of Interesting Subarrays

Medium

5

10

1

Minimum Edge Weight Equilibrium Queries in a Tree

Hard

6

LET’S DISCUSS THE QUESTIONS:

Problem 1: Count Symmetric Integers

Approach: In this question, we need to count the number of symmetric integers in the given range [low, high] by iterating through each integer in the range, converting it into a string, and checking if the absolute sum of differences between corresponding digits from the start and end of the string is zero. If it is then increments a counter and at the end returns the count of symmetric integers.

Time Complexity: O(n)
Auxiliary Space: O(1)

Problem 2: Minimum Operations to Make a Special Number

Approach: To solve this problem I initialize two boolean flags, fiveFound and zeroFound, to track whether the digits ‘5’ and ‘0’ have been found in the string, respectively. Iterate through the characters of the string from right to left. Check for various conditions: If both 0 and 5 have been found in the string, and the current character is either 0 or 5 then, return the difference between the current position and the position of the last 0 or 5 found. This represents the number of operations needed to make the string valid. If 0 has been found and the current character is 5, or 5 has been found and the current character is 2 or 7, return the difference between the current position and the position of the last 0or 5 found. If the current character is 0 set the zeroFound flag to true. If the current character is 5 set the fiveFound flag to true. If the loop completes without any of the above conditions being met so I can directly return n-1 .If none of the above conditions are met and zeroFound is still false, it means that the string is already valid, so return n as the minimum number of operations.

Time Complexity: O(n)
Auxiliary Space: O(1)

Problem 3: Count of Interesting Subarrays

Approach: In this question we need to counts the number of subarrays in the nums vector whose sum, when taken modulo mod, is equal to k. I uses a prefix sum approach and unordered map to efficiently track and calculate this count. At the end I return count of interesting subbarrays.

Time Complexity: O(n)
Auxiliary Space: O(1)

Problem 4: Minimum Edge Weight Equilibrium Queries in a Tree

Approach: To solve this problem, I try to use a depth-first search (DFS) algorithm to preprocess the tree and calculate the prefix sums of edge weights for each node. Then, for each node [ai, bi], I can calculate the answer by finding the lowest common ancestor (LCA) of ai and bi and using the prefix sums to compute the minimum number of operations needed. And last I got my anwser.

Time complexity: O(n*log⁡ n + q(C+ log ⁡n))
Auxiliary Space: O(n*log⁡ n)

Conclusion:

At the end of contest I was able to solve 3 questions and I got 12 out of 18 points in this contest. I waste lot of time to solve last question but I was not able to solve it.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads