Open In App

Contest Experiences | Leetcode bi-weekly contest #100

Last Updated : 09 Nov, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

About the Contest:

The contest was organized by LeetCode on March 18, 2023. It consisted of 4 questions and the time given to solve them was 1 hour 30 minutes i.e. 90 mins.

Link of the Contest: LeetCode Biweekly #100

Overview of the Questions:

Problem Name

Difficulty

Pre-Requisite

Time to Solve by Me

Number of Attempts

Distribute Money to Maximum Children

Easy (3 Points)

Math, Greedy

9 mins

2

Maximize Greatness of an Array

Medium (4 Points)

Two-Pointers, Greedy, String

5 mins

1

Find Score of an Array After Marking All Elements

Medium (4 Points)

Sorting, Heap(Priority Queue)

9 mins

1

Minimum Time to Repair Cars

Medium (5 Points)

Binary Search

25 mins

1

LET’S DISCUSS:

Problem 1: Distribute Money to Maximum Children:

My Experience: There couldn’t be a more humiliated start to a contest than this one. This was potentially one of the trickiest easy questions one will came across. Considering the fact that the first question had only 14% accuracy and 53000+ submissions, reflects how tricky it was to solve it. The question had a lot of edge cases to be considered while keeping in mind that each child must get exactly 8$. Designing own test cases often helps to understand the logic of the question. I didn’t got AC in my first attempt, then I utilized the weak constraints to solve the problem in O(N) complexity through one by one distribution.

Accepted Solution:

The best part about this problem is that it could be successfully solved in multiple ways with multiple complexities like O(1), O(log30), O(N), and even O(N^2). Firstly distribute 1 $ to each child. This is done to ensure that each child will have at least 1 $ Simultaneously, we got rid of 2nd condition mentioned in the question, thus, we now only have to concern about 1st and 3rd condition. Since, each child already have 1 $, we want to distribute 7$ more to as much children as possible. Money/7 will return me how much children can get entire 7$ thus making their totals 8. If Money % 7 == 3 (which is indirectly checking if a child has 4$), then we will distribute those 4 $ to two different children, hence, n – 2 children will be left who will have 8$. Else, it is possible to distribute money to all children.

Problem 2: Maximize Greatness of an Array:

My Experience: Comparatively this question took even less time to solve than the first question. The question wanted to explore all possible permutations of nums array, but after reading the constraints it was clear that there is no such need to get into permutation part as the maximum answer could be evaluated through just the sorted array itself using two pointer technique.

Accepted Solution:

The intuition behind this question is sorting. If a number in sorted array is greater than original array (pref[j] > nums[i]) then we can say greatness index is encountered so we increase the count(ans) and increment the i index in 1st array. In case if for an original array element nums[i], we are unable to find pref[j] such that pref[j] > nums[i], that means we are done with all the valid greatness pairs and no more pairs exist. The time complexity for the code will be O(NlogN) due to the sort function and the space complexity will be O(1).

Problem 3: Find Score of an Array After Marking All Elements:

My Experience: The third point in the question description was enough to provide the intuition for using priority queue in this question. I had solved problems of similar pattern in the past as well. Whenever the question wants you to find smallest, then next smallest, then next smallest, and so on, the best way to evaluate it is using priority queue. The coding part took some time due to medium typing speed, but the question was accepted in the first submission.

Accepted Solution:

The intuition from this question could be found through 3rd operation which wants to find repetitive minimum element in the array. This could be easily done in O(1) using priority queue or to be more specific, using min heap. The top of heap will always indicate the minimum element of the array. It is essential to note that we want to mark these elements hence we use a visited array of size n, where vis[i] indicates whether ith index element is visited or not. We will only add the minimum element’s value to our answer if it is not visited already. Alongside this, we check for indexes i – 1 and i + 1. If they exist, and their respective values are not visited, so we mark them visited. Also, it’s important to consider long long. Time complexity for the code will be O(N) and the space complexity will be O(N).

Problem 4: Minimum Time to Repair Cars

My Experience: Every time solving a hard question, the key is to to identify keywords and phrases that indicates certain fixed pattern through which it becomes easier to evaluate and solve them. This tip helped to find the intuition for this question. The main phrase to consider here was that we want all cars to be repaired in minimum possible time. This phrase was sufficient to provide a hint foe using the concept of binary search on answer. Again, the typing speed was moderate as I was concerned with the end limits of the binary search. At last, I was able to submit the question without any penalty on the first try itself.

Accepted Solution:

We know a mechanic can repair a car in rank[i] * n2 time, hence, there could be multiple orientations of all n mechanics working separately or simultaneously. However, since we want all the cars to me repaired in minimum possible time, we can use the concept of binary search on answer. The aim is to provide a fixed time to all mechanics, say ‘mid’ minutes. If in these mid minutes, all the mechanics can repair atleast ‘cars’ cars, then that mid will be a potential answer. However, we want to find the minimum possible value of this ‘mid’ time, hence we reduce the search space to left half only by making high = mid – 1. Else, if it is not possible to repair ‘cars’ cars by the end of ‘mid’ minutes, the mechanics dont have sufficient time to repair all cars, hence, we want to increase ‘mid’ time allocated to them by making low = mid + 1. The initial value of end limits will be low = 1 and high = 1e14 as the operations could go over the integer limit. The time complexity for the following approach will be O(NlogN).

Conclusion:

Well leetcode would surely have thought to make 100th Biweekly a memorable one, but it turned out to be a moderate one. In fact the pattern was different from the usual contests having 1 Easy – 3 Med instead of 1 Easy – 2 Med – 1 Hard. Considering the fact that the easy problem had 53000+ submissions and 14% accuracy, reflects how bizarre the evening was. The contest post received a lot of downvotes after the contest ended. The medium questions were not very difficult and moreover all three of them were based on fix patterns. If one could identify those patterns and the data structures to solve them it becomes just a matter of implementing. Even the last medium question had very much submissions by the end of the contest.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads