Open In App

Contest Experiences | LeetCode Weekly Contest #363

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

About the Contest:

This weekly contest was organized by Leetcode on 17 Sep 2023 from 8 AM to 9.30 AM total of 90 minutes. In this contest, there is a total of 4 problem statements and you need to solve this question in a given time slot. 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.

Winning Prizes:

  • 1st ranked – an Apple HomePod mini
  • 2nd ranked – a Logitech G903 LIGHTSPEED Gaming Mouse
  • 3rd to 5th ranked – LeetCode Backpack
  • 6th to 10th ranked – LeetCode water bottle
  • 11th to 20th ranked – LeetCode Big O Notebook

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

Overview of the Questions:

Question Name

Difficulty

Pre-requisite

Approx time to solve by me

Number of Submissions by me

Sum of Values at Indices With K Set Bits

Easy(3 points)

bit manipulation

3 mins

1

Happy Students

Medium (4 points)

Sorting

10 mins

1

Maximum Number of Alloys

Medium (5 points)

Binary Search

25 mins

2 (1 WA)

Maximum Element-Sum of a Complete Subset of Indices

Hard (6 points)

Let’s Discuss the above problems:

Problem 1: Sum of Values at Indices With K Set Bits

Difficulty level – Easy
Approach – The first problem of leetcode contest is always easy and the problem statement will be given straightforward. In this problem we have to calculate the sum of the elements of those who’s binary representation of the index having the count of 1 equals to the given interger K. We just need iterate onn the array and count the set bits of the the i-th index and if it is equal to the K then add the i-th index element to the ans. At the end return the ans;

Time Complexity – O(N)
Space Complexity – O(1)

Problem 2: Happy Students

Difficulty level – Medium
Approach – This problem was a bit confusing to understand and I rate hardest medium problem, to solve this problem I first sorted the nums array. After sorting the nums array it’s become easier to keep track of number of students in the group for an i-th index which is (i+1). So after sorting the array: For each ith index if (i+1) > nums[i] means we have taken (i+1) students and all students [0……i] has (i+1) > nums[i] since the array is sorted. For remaining students if (i+1)< nums[i+1] means for all students[i+1…..n] we have (i+1) < nums[i+1] since the array is sorted. Increment the counter if this condition hits true and in the last return the counter interger.

Time Complexity – O(N log N), due to sorting the nums array.
Space Complexity – O(1)

Problem 3: Maximum Number of Alloys

Difficulty level – Medium
Approach – It is an easy-medium question just because of the too many variables and stuff it become a bit complicated problem to understand. In this problem we have to return the maximum number of alloys that the company can create with the same machine. Each machine can make same X alloys within a budget and we have to maximize the X. To calculate the X for each machine I have used binary search because of if maximum number of alloys to be formed is X then we can always form less than X number of alloys and this will return the maximum number no X allay can be made from a machine. When we fixed set of alloys to be produced, denoted as “mid,” I have calculated the minimum budget needed to manufacture this specific quantity of alloys using mid. To find this minimum budget, I have iterate through each machine and calculated the budget required for each of them. If, during this process, I find that the calculated budget is less than the allocated budget, I return a “true” result, indicating that it is possible to produce the desired quantity of alloys, “mid” (X) within the given budget.

Time Complexity – O(log N * N).
Space Complexity – O(1)

Problem 4: Maximum Element-Sum of a Complete Subset of Indices

Difficulty level – hard
Remark – I was not able to solve this problem in live contest.

Conclusion:

At the end of the contest I was able to solve 3 questions and got 12 points out of 18 points in this contest. The last question was a bit tricky due to it wasn’t able to solve. Try to understand the problem first and then code your solution but check for corner cases always due to it I made a wrong submission in 3rd problem.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads