Open In App

Contest Experience: LeetCode Weekly Contest 332

Last Updated : 27 Sep, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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:

  • get a Maximum point out of 18.
  • Minimum time to solve these questions.
  • One wrong submission was a 5-minute extra penalty time.

Bonus Prizes:

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

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

OVERVIEW OF CONTEST QUESTIONS:

Problem Name

Difficulty

Total Points

Approx. time taken by me

Number of Submissions by me

Find the Array Concatenation Value

Easy

3

5

1

Count the Number of Fair Pairs

Medium

4

8

1

Substring XOR Queries

Medium

5

10

2 ( 1 WA)

Subsequence With the Minimum Score

Hard

6

20

2

Problem 1: Find the Array Concatenation Value

Approach: 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 Pairs

Approach: 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 Queries

Approach: 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 Score

Approach: 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.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads