![]() |
ABOUT THE CONTEST: LEETCODE #WEEKLY CONTEST 361This weakly contest was organized by Leetcode on 3 Sep 2023. In this contest, there is a total of 4 problem statements and you need to solve this question in a given time slot. 90 minutes are provided to solve these questions. The ranking was based on the following:
⭐ Bonus Prizes⭐
Link of the Contest: https://leetcode.com/contest/weekly-contest-361/ OVERVIEW OF ALL CONTEST QUESTIONS:
LET’S DISCUSS THE QUESTIONS:Problem 1: Count Symmetric Integers Approach: In this question, we need to count the number of symmetric integers in the given range [low, high] by iterating through each integer in the range, converting it into a string, and checking if the absolute sum of differences between corresponding digits from the start and end of the string is zero. If it is then increments a counter and at the end returns the count of symmetric integers. Time Complexity: O(n) Problem 2: Minimum Operations to Make a Special Number Approach: To solve this problem I initialize two boolean flags, fiveFound and zeroFound, to track whether the digits ‘5’ and ‘0’ have been found in the string, respectively. Iterate through the characters of the string from right to left. Check for various conditions: If both 0 and 5 have been found in the string, and the current character is either 0 or 5 then, return the difference between the current position and the position of the last 0 or 5 found. This represents the number of operations needed to make the string valid. If 0 has been found and the current character is 5, or 5 has been found and the current character is 2 or 7, return the difference between the current position and the position of the last 0or 5 found. If the current character is 0 set the zeroFound flag to true. If the current character is 5 set the fiveFound flag to true. If the loop completes without any of the above conditions being met so I can directly return n-1 .If none of the above conditions are met and zeroFound is still false, it means that the string is already valid, so return n as the minimum number of operations. Time Complexity: O(n) Problem 3: Count of Interesting Subarrays Approach: In this question we need to counts the number of subarrays in the nums vector whose sum, when taken modulo mod, is equal to k. I uses a prefix sum approach and unordered map to efficiently track and calculate this count. At the end I return count of interesting subbarrays. Time Complexity: O(n) Problem 4: Minimum Edge Weight Equilibrium Queries in a Tree Approach: To solve this problem, I try to use a depth-first search (DFS) algorithm to preprocess the tree and calculate the prefix sums of edge weights for each node. Then, for each node [ai, bi], I can calculate the answer by finding the lowest common ancestor (LCA) of ai and bi and using the prefix sums to compute the minimum number of operations needed. And last I got my anwser. Time complexity: O(n*log n + q(C+ log n)) Conclusion: At the end of contest I was able to solve 3 questions and I got 12 out of 18 points in this contest. I waste lot of time to solve last question but I was not able to solve it. |
Reffered: https://www.geeksforgeeks.org
Contest Experiences |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 11 |