Open In App

Contest Experiences | LeetCode: Weekly Contest #334

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

About the contest: LeetCode Weekly Contest #334

Leetcode weekly contests are held virtually every weekend on their platform. These contests are helpful for programmers to test their coding skills by competing with coders worldwide. The plagiarism detector and community support on leetcode play an important role in ensuring fairness in the contest. Rankings were based on the following:

  • Maximum points
  • Minimum time to solve
  • The penalty for 1 wrong submission was 5 mins.

Prizes/Offers:

Leetcode always gives amazing goodies to rank holders from 1 to 20:

leetcode_goodies

#334 contest was sponsored by leetcode only so it offered interview opportunities also to some top performers.

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

The duration of the contest was just 90 min and has ended but you can try hands-on the questions through this link. Your submissions won’t be considered for ratings.

Overview of all question:

Problem Name

Difficulty

Total Points

Approx. time taken by me

Number of Submissions

Left and Right Sum Differences

Easy

3/3

8

1

Find the Divisibility Array of a String

Medium

3/4

15

2

Find the Maximum Number of Marked Indices

Medium

0/5

25

3 ( All 3 WA )

Minimum Time to Visit a Cell In a Grid

Hard

0/6

Problem 1: Left and Right Sum Differences

The contest first problem always has maximum submissions as it is easy/medium level. It could be solved easily if you know operations on array.

Approach: I stored left sum in an array and right sum in another array. The result array is calculated by subtracting the right sum array from left sum sum array. This question uses the concept of prefix sum and suffix sum. The constraints are satisfied by this brute force approach of Time and space complexity O(n). This question worked fine withour optimization.

Problem 2: Find the Divisibility Array of a String

Approach: This question dealt with prefix and array. At first I tried to store each prefix in extra integera variable and then divide it but that exceeded time as per given constraints. The optimised way to do this is to check divisibity of end integer of each prefix by simply traversing through the string. rem = (rem * 10 + int(i)) % m; // in this way we calculate the remainder by traversing the string and not creating any extra space.

Problem 3: Find the Maximum Number of Marked Indices

Approach: This question seemed to be easy but got stuck on it. While solving this, take care that marked indices are not counted again. I could not figure out the correct solution during contest but was able to solve after some brainstorming. Sort the array for this approach of complexity O(n*logn). The pairs of indices should be searched by partitioning the array into halves. The index i will be the lowest value among first half of array, this ith element should be checked to pair up with smallest value among other half of array. Since we sorted the array we dont need to worry about marking the visited index .

Problem 4: Minimum Time to Visit a Cell In a Grid

Approach: I was not able to build approach for this question but it can be solved using a variation of Dijkstra’s algorithm, here movement is possible if time taked is greater than the value of next cell. The algorithm works different even number of seconds and odd number of seconds are left.

Conclusion:

In the end, I got a total [ 6/18 ] points and secured a rank of 10309 out of 22908 participants. I will try my best to solve all the question in the upcoming weekly contest.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads