Open In App

Contest Experiences | LeetCode: Biweekly Contest #98

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

About the contest: This contest was organized by Leetcode on Feb 18th, it consisted of 4 questions and the time given to solve them was 1 hour 30 minutes i.e. 90 mins.

WINNING PRIZES: It was a regular contest sponsored by Leetcode thus it only had Leetcoins for the top performers.

RANK

PRIZE (Coins)

1

5000

2

2500

3

1000

4 – 50th

300

51 – 100th

100

101 – 200th

50

Participation

5

Link of the contest: 98th Leetcode Biweekly Contest

Overview of the questions:

Problem Name

Difficulty

Pre-requisite

Time to solve by me

Number of Attempts

Maximum Difference by Remapping a Digit

Easy (3 Points)

Greedy

10 mins

1

Minimum Score by Changing Two Elements

Medium (4 Points)

Greedy and Sorting

13 mins

1

Minimum Impossible OR

Medium (5 Points)

Array and Bit-Manipulation

15 mins

1

Handling Sum Queries After Update

Hard (7 Points)

Segment Tree

50 mins

2 (Both TLE)

LET’S DISCUSS:

Problem 1: Maximum Difference by Remapping a Digit
My Experience: As usual like all other contests, the first question was a cakewalk problem. However, I took some time to analyze with which language can I solve this question the quickest. At last I solved it using in-built python functions.
Accepted Solution: Just use the logic that for minimal value, replace all occurrences of the first digit with ‘0’s and for maximal value, replace the first non-‘9’ digit with ‘9’. This could be done in O(log (num)) time complexity.

Problem 2: Minimum Score by Changing Two Elements
My Experience: This question didn’t involved use of any data structure as such because it was moreover based upon greedy algorithm. Sorting the array will be the biggest hint to solve this problem.
Accepted Solution: Simply sort the array and compare the absolute differences of smallest 3 elements with the largest 3 elements. The answer will be the minimalist difference among the 3 pairs. This could be done in O(log(N)) time complexity.

Problem 3: Minimum Impossible OR
My Experience: The question’s language had a complex bitwise expression. Once evaluation that expression, the question boils down to a standard pattern problem which can be easily solved using greedy algorithm.
Accepted Solution: Simply create a hashmap of the array. Then iterate over for loop of range 0 to 32 and identify the first power of 2 or smallest power of 2 that is not present in the hashmap. This could also be done greedily by checking what is the smallest power of 2 present in the array. This could be done in O(N) time complexity.

Problem 4: Handling Sum Queries After Update
My Experience: If anyone have simplest of understanding about the format of query-range questions, he/she can easily identify that it belongs to segment tree category. The question was tagged hard and revolved around standard range-query pattern in segment trees. I tried to solve the question using lazy propagation methodology, and was able to write complete code before the end of contest, but upon submitting, It gave a time-limit-exceeded error. I tried to analyze it again and resubmit it, but it got into the same tle error.
Accepted Solution: Notably we had to perform the following operations on the queries array:

  • For Propagation function, if the parent node has the mark to flip, then we update it with summation of all children nodes.
  • This propagation function will work every time we need to access to the children nodes whenever we want to invoke the functions.
  • For the Update function, we simply mark the flipping operation and update the summation, or we can just iterate with children nodes with lazy propagation.
  • Lastly for Query function, we have to collect the summation from children nodes using the lazy propagation.

Conclusion:

Like other biweekly contests this contest was also rich into multiple DSA fundamental algorithms. Usually I manage to solve 3 and sometimes 4 as well, but in this contest I would’ve solved all 4 easily had the TLE not occurred in the last question. The takeaway was to never underestimate any data structure and cover every algorithm with equal determination whilst not making any predictions that it would never be asked.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads