![]() |
About the Contest: On 12 Feb 2023, this contest was organized on Leetcode. In the given contest there are 4 questions and 1 hour 30 min time to solve these questions. The ranking was based on the following:
Bonus Prizes:
Link of the Contest: https://leetcode.com/contest/weekly-contest-332/ OVERVIEW OF CONTEST QUESTIONS:
Problem 1: Find the Array Concatenation ValueApproach: In this questions calculates the concatenation value of integers in a vector by taking pairs of integers from the start and end of the vector, concatenating their digits, and sum these concatenated values. Initialize ans to 0 and two pointers s and e at the start and end of the nums array. In a loop, while s is less than or equal to e .If s and e are at the same position, simply add the value at that position to ans. Otherwise, convert the integers at positions s and e into strings, concatenate them and convert the resulting string back into an integer. Add this integer to ans. At the end, return the ans . Time complexity : O(N) Space complexity : O(1) Problem 2: Count the Number of Fair PairsApproach: In this questions counts the number of fair pairs in a list of numbers. A fair pair is a pair where the sum is within a given range and the first number in the pair comes before the second in the pair in given list. First sorts these list. Then use two pointers (i and j) to find these pairs. It efficiently calculates the count of valid pairs for each element using std::upper_bound. At the end it is returned the count of number of fair pairs. Time complexity : O(n*log(n)) Space complexity : O(1) Problem 3: Substring XOR QueriesApproach: In this question each query is a pair of integers [a, b]. Question goal is to find substrings in given string ‘s’ whose XOR is equal to a ^ b for each query. First in string s, calculating XOR values of substrings and storing their positions in a map. For each query, it computes num = a ^ b and checks if the map found this num. If found, it adds the corresponding substring’s starting and ending positions to the answer vector ans. If not found, it adds [-1, -1] to ans to indicate that no matching substring . Finally, it returns ans, which is answers to all queries. Time complexity : O(32*n) Space complexity : O(32*n) ( Worst ) Problem 4: Subsequence With the Minimum ScoreApproach: In this question we need finds the minimum number of character deletions required to transform one string S into another string T. I uses binary search approach to efficiently find the minimum score. First I initializes two pointers lo and hi for binary search. The check method checks if a given length len of the right subarray in T can be deleted to match S. It iteratively adjusts lo and hi in the binary search loop until the minimum score is found. Finally, returns the minimum score as hi + 1. Time complexity : O(n * log(m)) Space complexity : O(m) Conclusion: The questions was not to difficult to this contest. At the end I solve all 4 questions in 43 min and I got 18 out of 18 points. All the best for upcoming contests. |
Reffered: https://www.geeksforgeeks.org
Contest Experiences |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |