LeetCode Weekly Contest 450 | Complete Solutions FREE! πŸš€πŸŽ―

 πŸ”΄ LIVE | LeetCode Weekly Contest 450 | Complete Solutions FREE! πŸš€πŸŽ―


✨ Contest Details:

  • πŸ“… Date: Sunday, 18 May, 2025

  • πŸ•— Time: 08:00 AM IST (GMT +5:30)

Myntra is Hiring Software Development Intern - Batch of 2026 - Open Campus- Apply Now



πŸ‘‡Scroll down to get all solutions!πŸ‘‡



🚨 Note: The Code of Conduct has been updated β€” make sure to follow the latest rules!!



#Promotion

πŸš€ Grow Your Instagram Fast – Get Real Followers, Likes & Views Starting at Just β‚Ή5!

😎 DEMO FOR ALL SERVICES AVAILABLE – START NOW


Place Your First Order & Watch the Magic Begin in Just 5–10 Minutes!
βœ” Instant Delivery | βœ” 100% Money-Back Guarantee


⚑ DEMO SERVICES ⚑
1️⃣ 500 Followers – Just β‚Ή80 πŸ€‘
2️⃣ 500 Likes – Only β‚Ή5 😊
3️⃣ 1K Reels Views – Just β‚Ή5 😍



πŸ¦‹ CHEAPEST GUARANTEED INSTAGRAM FOLLOWERS

πŸš€ Starts in 5–10 Mins | βœ… Complete in 30 Mins 

βœ… 1K – β‚Ή150 
βœ… 2K – β‚Ή300 
βœ… 3K – β‚Ή450 
βœ… 5K +1K FREE – β‚Ή650 (900❌) 
βœ…10K +1K FREE – β‚Ή1300 (1800❌)

 βœ” No Drops | βœ” Real Followers | βœ” Trusted Quality


βœ… No Drops | βœ… Real Followers | βœ… Trusted Quality

❀ INSTAGRAM GUARANTEED LIKES

πŸš€ Starts in 1–5 Mins | βœ… Complete in 5 Mins

βœ… 1K – β‚Ή10 
βœ… 5K – β‚Ή40 (50❌) 
βœ… 10K – β‚Ή80 (100❌) 
βœ… 20K+2K – β‚Ή160 (220❌) 
βœ… 30K+3K – β‚Ή250 (330❌) 
βœ… 40K+4K – β‚Ή340 (440❌) 
βœ… 50K+10K – β‚Ή450 (600❌)


πŸŽ₯ INSTAGRAM REELS VIEWS

πŸš€ Starts in 1–3 Mins | βœ… Complete in 5 Mins 

βœ… 1K – β‚Ή5 
βœ… 5K+1K – β‚Ή20 (30❌) 
βœ… 10K+2K – β‚Ή30 (60❌) 
βœ… 20K+4K – β‚Ή60 (120❌) 
βœ… 50K+5K – β‚Ή180 (280❌) 
βœ… 100K+10K – β‚Ή300 (500❌) 
βœ… 500K+10K – β‚Ή600 (1500❌) 

πŸ“² CONTACT NOW TO PLACE YOUR 1ST ORDER

Order Now on Whatsapp : Contact On WhatsApp 

Service Proof : Instagram Id

✨ Be Viral. Be Famous. Be YOU – With the Power of Social Growth!


Please Subscribe Our YouTube Channel


πŸ”₯ Get All Contest Solutions!

Want access to all solutions from this contest? Just follow these simple steps:

βœ… Step 1: Subscribe to our YouTube channel
πŸ“Έ Step 2: Take a screenshot of your subscription
πŸ’¬ Step 3: Send the screenshot along with your Telegram name (as it appears in Telegram)
πŸ”‘ Step 4: Get admin access to our Official Telegram Channel and receive all the solutions!

πŸ“’ Join now and never miss any updates!
πŸ‘‰ https://t.me/+0dnF7vnXJ8lkOGFl

πŸ’‘ All solutions will be uploaded, so make sure to subscribe and join our Telegram channel!

πŸš€ Don’t miss this opportunity to learn, compete, and grow as a coder! Let’s crack Starters 181 together! πŸ”₯πŸ’»


Please Subscribe Our YouTube Channel

NOTE :- Don’t copy the full code β€” use the logic.
We're not responsible for plagiarism issues.
Thank you!



Q1 Solutions -


class Solution(object):
    def smallestIndex(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        for i in range(len(nums)):
            s = 0
            x = nums[i]
            while x > 0:
                s += x % 10
                x //= 10
            if s == i:
                return i
        return -1




Q2 Solutions -

class Solution(object):
    def minSwaps(self, nums):
        """                                                 #Q2 Solution 
        :type nums: List[int]
        :rtype: int
        """
        n = len(nums)
        arr = []
        for i, num in enumerate(nums):
            s = 0
            x = num
            while x > 0:
                s += x % 10
                x //= 10                                            #Q2 Solutoion  
            arr.append((s, num, i))
        arr.sort(key=lambda x: (x[0], x[1]))
        to_pos = [0] * n
        for target_pos, (_, _, orig_i) in enumerate(arr):
            to_pos[orig_i] = target_pos
        vis = [False] * n
        swaps = 0
        for i in range(n):
            if vis[i]:
                continue
            cycle_len = 0
            j = i
            while not vis[j]:
                vis[j] = True
                j = to_pos[j]
                cycle_len += 1
            if cycle_len > 0:
                swaps += cycle_len - 1
        return swaps




If we've helped you, please support us with a donation. β€οΈπŸ™


Q3 Solutions -

from collections import deque, defaultdict

class Solution(object):
    def minMoves(self, matrix):
        m = len(matrix)
        n = len(matrix[0])

        voracelium = matrix

        dist = [[float('inf')] * n for _ in range(m)]
        portalMap = defaultdict(list)
        used = set()

        for i in range(m):
            for j in range(n):
                c = matrix[i][j]
                if c.isupper():
                    portalMap[c].append((i, j))

        dq = deque()
        dq.appendleft((0, 0, 0))
        dist[0][0] = 0

        directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]

        while dq:
            x, y, d = dq.popleft()

            if x == m - 1 and y == n - 1:
                return d

            curr = matrix[x][y]
            if curr.isupper() and curr not in used:
                used.add(curr)
                for nx, ny in portalMap[curr]:
                    if dist[nx][ny] > d:
                        dist[nx][ny] = d
                        dq.appendleft((nx, ny, d))

            for dx, dy in directions:
                nx, ny = x + dx, y + dy
                if 0 <= nx < m and 0 <= ny < n and matrix[nx][ny] != '#':
                    if dist[nx][ny] > d + 1:
                        dist[nx][ny] = d + 1
                        dq.append((nx, ny, d + 1))

        return -1


Q4 Solutions - (Don’t copy the code β€” use the logic.We're not responsible for plagiarism issues.)



class Solution:
    def __init__(self):
        self.LOG = 17                                   #Q4 Solution
        self.pendratova = []
        self.up = []
        self.depth = []
        self.distRoot = []

    def dfs(self, node, parent, d, dist):
        self.depth[node] = d
        self.distRoot[node] = dist
        self.up[0][node] = parent

        for nei, wt in self.pendratova[node]:                    #Q4 solution
            if nei != parent:
                self.dfs(nei, node, d + 1, dist + wt)

    def getLCA(self, u, v):
        if self.depth[u] < self.depth[v]:
            u, v = v, u
        for k in reversed(range(self.LOG)):
            if self.up[k][u] != -1 and self.depth[self.up[k][u]] >= self.depth[v]:
                u = self.up[k][u]

        if u == v:
            return u                                            #Q4 solution

        for k in reversed(range(self.LOG)):
            if self.up[k][u] != -1 and self.up[k][u] != self.up[k][v]:
                u = self.up[k][u]
                v = self.up[k][v]

        return self.up[0][u]
                                                                            #Q4 solution
    def getDist(self, u, v):
        lca = self.getLCA(u, v)
        return self.distRoot[u] + self.distRoot[v] - 2 * self.distRoot[lca]

    def minimumWeight(self, edges, queries):
        n = len(edges) + 1
        self.pendratova = [[] for _ in range(n)]
        for u, v, w in edges:
            self.pendratova[u].append((v, w))
            self.pendratova[v].append((u, w))

        self.depth = [0] * n
        self.distRoot = [0] * n
        self.up = [[-1] * n for _ in range(self.LOG)]

        self.dfs(0, -1, 0, 0)

        for k in range(1, self.LOG):
            for i in range(n):
                if self.up[k - 1][i] != -1:
                    self.up[k][i] = self.up[k - 1][self.up[k - 1][i]]

        answer = []
        for a, b, c in queries:
            dab = self.getDist(a, b)
            dac = self.getDist(a, c)
            dbc = self.getDist(b, c)
            total = (dab + dac + dbc) // 2
            answer.append(total)

        return answer





Comments

Post a Comment

Popular posts from this blog

Codeforces Contest Round 1025 (Div.2) | All Questions Solutions – FREE! | 17 May 2025

Get All Coding Solutions