Open In App

Contest Experience | LeetCode Weekly Contest 365

Last Updated : 13 Oct, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

ABOUT THE CONTEST: LEETCODE #WEEKLY CONTEST 365

On 2 Oct 2023, this weekly contest was organized by leetcode. In this contest, there is a total 4 questions and you need to solve this question in a given time slot. 1 Hour 30 min time given to you to solve these questions. The rank was based on the following:

  • Maximum score.
  • Minimum time.
  • penalty time of 5 minutes for each wrong submission.

Bonus Prizes:

  1. 1st Rank: Apple HomePod mini
  2. 2nd Rank: Logitech G903 LIGHTSPEED Gaming Mouse
  3. 3rd to 5th Rank: LeetCode Backpack
  4. 6th to 10th Rank: LeetCode water bottle
  5. 11th to 20th Rank: LeetCode Big O Notebook

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

OVERVIEW OF ALL CONTEST QUESTIONS:

Question Name

Difficulty

Total score

Approx. time is taken by me

Number of Submissions by me

Maximum Value of an Ordered Triplet I

Easy

3

5

1

Maximum Value of an Ordered Triplet II

Medium

4

5

1

Minimum Size Subarray in Infinite Array

Medium

5

10

2 ( 1 WA )

Count Visited Nodes in a Directed Graph

Hard

6

15

2 ( 1 TLE )

Coding Questions:

Problem 1: Maximum Value of an Ordered Triplet I

Approach: To solve this questions first I declare some variable to store some values. Variables are mab and ma. For each iteration in nums, we update this variable values. mab is the maximum value of pair (A[i] – A[j]). ma is the maximum value of element A[i]. res is the maximum value of a triplet (A[i] – A[j]) * A[k]. At the end I return maximum value of res.

Time Complexity: O(n)
Auxiliary Space: O(1)

Problem 2: Maximum Value of an Ordered Triplet II

Approach: Follow same approach for first problem. Which is most optimal approach.

Time Complexity: O(n)
Auxiliary Space: O(1)

Problem 3: Minimum Size Subarray in Infinite Array

Approach: In given question we need to finds the minimum length of a subarray to this vector nums such that the sum of its elements is at least target. We need to first calculate the total sum of the elements in nums. If target is greater than the total sum, then we calculate the module of total sum. If target is zero, the entire array already satisfies the condition, so return 0. Double the size of nums to consider circular subarrays. Use a sliding window approach to find the minimum subarray length that satisfies the condition. At the end we return the minimum length found.

Time Complexity: O(n)
Auxiliary Space: O(n) ( For map )

Problem 4: Count Visited Nodes in a Directed Graph

Approach: To solve this graph problem i use topological sorting approach to identify cycles in a directed graph and then processes nodes accordingly. Calculate the indegree (number of incoming edges) for each node in the graph. Initialize a queue and add nodes with an indegree of 0 to it. Process the nodes one by one from the queue, marking them as visited. Reduce the indegree of neighboring nodes by 1. If a neighbor’s indegree becomes 0, add them into the queue. After this step, I visited all nodes that are not part of any cycle. For each unvisited node, calculate its cycle length and update the answer for nodes with that cycle. Mark these nodes as visited to avoid revisiting the same cycle. Now, I to calculate answers for nodes that were not part of any cycle. To do this, I process these nodes in reverse order of their visitation. Use a stack to store them so that you have the most recently visited node at the top of the stack and the others below it. At the end I return ans.

Time Complexity: O(n)
Auxiliary Space: O(n)

Conclusion:

I was able to solve all 4 questions in this contest. Questions was not to difficult. I require 30-35 min to solve this questions. All the best for next contest.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads