Open In App

Contest Experiences | LeetCode #Biweekly Contest 95

About the contest: LeetCode #Biweekly Contest 95

This contest was organized by Leetcode on Jan 7th, 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: 95th Leetcode Biweekly Contest



Overview of the questions:

Problem Name

Difficulty

Pre-Requisite

Time to solve by me

Number of Attempts

Categorize Box According to the Criteria

Easy (3 points)

Math

6 mins

1

Find Consecutive Integers from a Data Stream

Medium (4 points)

Hash Table, Queue and Counting

10 mins

2

Find Xor-Beauty of Array

Medium (5 points)

Array, Math, and Bit Manipulation

13 mins

1

Maximize the Minimum Powered City

Hard (6 points)

Array, Binary Search, Queue, Sliding Window and Greedy

60 mins

2 (Both WA)

LET’S DISCUSS:

Problem 1: Categorize the Box According to the Criteria

My Experience: As usual like all other contests, the first question was a cakewalk problem. One of the easiest problems even for beginners. Just simple question reading and implementation. Nothing complicated, You only have to do what is stated.



Accepted Solution:

Follow the stated instruction given in problem only. The time and complexity of the code was O(1).

Problem 2: Find Consecutive Integers from a Data Stream

My Experience: This question was a design question. One was supposed to design a class that Returns true if the last ‘k’ integers are equal to value ‘x’. As soon as I read the statement “last k integers”, Stack data structure immediately striked into my mind.
I tried to check last k elements using ‘k’ pop operations from stack, but my approach yielded WA. Later I found out it could be easily solved without any data structure.

Accepted Solution:

The question could simply be solved without using any data structure or extra space. All what you need to store is just a count integer which increments whenever num is equal to ‘x’ value upon calling consec() function. Create global variables inside the constructor to make ‘value’ and ‘k’ parameters global along with a count variable which will be initialised to 0 in the constructor. In the consec() function, if (num == x) increment count or else reset count to 0. The time and space complexity are O(1).

Problem 3: Find Xor-Beauty of Array

My Experience: This according to me was potentially the easiest medium question on the platform. Even the code was smaller than the question. Yet it took me entire 12 minutes to identify the pattern in the test cases. They gave an entire 10 SIZED ARRAY in the test case, not even a 4-5 length one. I was surprised to see that the XOR of entire array came out to be expected answer. This hold true for both the test cases. Therefore I gave it a try and coded it within 1 min. Fortunately, it passed all test cases and my rank rose by 6000+ spots.

Accepted Solution:

The question’s approach was to simply find out the XOR of entire array. You might not believe a medium question would turn out to be just 3 lines of code, but based on the ’10 length array’ test case and 10^5 constraints, the question hinted on calculating the xor value. Providing the technical reason, The question description followed the XOR commutative property:
type 2: (a | b) & b = (b | a) & b => ((a | b) & b) ^ ((b | a) & b) = 0
type 3: (a | b) & c = (b | a) & c => ((a | b) & c) ^ ((b | a) & c) = 0
Therefore the answer would be a ^ b ^ c. The time complexity of the approach was O(N).

Problem 4: Maximize the Minimum Powered City

My Experience: Being honest, after the third question got accepted, my adrenaline was at the peak aiming for an under 500 rank. But unlike usual contests, this D problem was a comparatively difficult one. Whenever I read the term Minimize the maximum value or Maximize the minimum value, I wonder how it could be solved using binary search. I tried binary search approach. My intuition was to check if it is possible to achieve a minimum power of min_power with the given number of power stations. If the power of the next city is already greater than or equal to the required minimum power, we don’t need to add any power stations. However my approach didn’t worked for some basic testcases and at last I ended up struggling entire 60 mins on the question. I submitted my solution twice, but both gave wrong answers upon submission.

Accepted Solution:

The question was indeed of binary search topic tag. However, the question involved topic tags of greedy and sliding window as well. More formally, one had to use binary search + sliding window methodology to solve the question. Apply binary search on answer concept where low = 0 and high = 1e11. Consider the first index with value less than mid as l and the last index with value less than mid as r. If the span of this [l, r] is less than (2*range + 1) then we can simply traverse vector v(current power of all cities) from l to r, find minimum value in it and then simply decrease k by (mid – minimum_value). Else, as soon as we reach such l, We can increase the next 2*range values by mid-a[l]. The time complexity of the expected solution was O(NlogN).

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 deeply struggled on 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.


Article Tags :