Open In App

Contest Experiences | LeetCode #Weekly Contest 326

ABOUT THE CONTEST: LEETCODE #WEEKLY CONTEST 326

This contest was organized by leetcode on 1 January 2023. In this contest, there are 4 questions, and 90 min given to you to solve these questions. The ranking was based on the following:

LINK OF THE CONTEST: https://leetcode.com/contest/weekly-contest-326/



OVERVIEW OF ALL CONTEST QUESTIONS:

Problem Name

Difficulty

Total Points

Approx. time taken by me

Number of Submissions by me

Count the Digits That Divide a Number

Easy

3

7

1

Distinct Prime Factors of Product of Array

Medium

4

10

1

Partition String Into Substrings With Values at Most K

Medium

5

10

1

Closest Prime Numbers in Range

Medium

5

20

1

LET’S DISCUSS THE QUESTIONS:

Problem 1: Count the Digits That Divide a Number

Approach: Initialize a variable ans to count the matching digits. Create a copy of num named num1 for processing. Start a loop that continues until num1 becomes 0. Get the last digit of num1 by taking the remainder when divided by 10. If divisible, increment the ans. Remove the last digit by integer division by 10. Return the (ans) count of digits that is divide num.



Time complexity : O(N)

Space complexity : O(1)

Problem 2: Distinct Prime Factors of Product of Array

Approach: This code counts the total number of distinct prime factors to given vector of integers. To solve this iterating through the numbers and factorizing each one to find its prime factors, and storing them into set. The size of the set at the end represents the count of distinct prime factors.

Time complexity : O(n*sqrt(Max_num))

Space complexity : O(k)

Problem 3: Partition String Into Substrings With Values at Most K

Approach: Find the counts how many minimum partitions can be formed, such that each partition represents an integer, and no integer in any partition greater than k. It iterates through the string, accumulating digits to form integers. When the integer greater than k, it starts a new partition and counts increase. The code returns the minimum number of partitions required to satisfy this condition or -1 if it is not possible.

Time complexity : O(N)

Space complexity : O(1)

Problem 4: Closest Prime Numbers in Range

Approach: We need to find the pair of prime numbers with the smallest difference within a given range [left, right]. is use to array which store identify of prime numbers in that range, then calculates the difference between adjacent primes to find the closest pair. If a pair is found, it returns {l, r} otherwise, it returns {-1, -1}.

Time complexity : O(Right * log(log(Right)))

Space complexity : O(Right)

Conclusion:

At the end, I solve all 4 question and I got 17 out of 17 points. I give my best for this Contest.

Article Tags :