fa
Feedback
Leetcode with dani

Leetcode with dani

رفتن به کانال در Telegram

Join us and let's tackle leet code questions together: improve your problem-solving skills Preparing for coding interviews learning new algorithms and data structures connect with other coding enthusiasts

نمایش بیشتر
1 259
مشترکین
اطلاعاتی وجود ندارد24 ساعت
+17 روز
-730 روز
آرشیو پست ها
Repost from A2SV - Discussion
Hello fellow coders, After a brief break, we've returned! Get ready for our fun weekly community coding contest happening every Saturday 🗓. It's your chance to compete with other awesome programmers, learn more about coding, and, most importantly, have a great time! 🥳 🏆 Contest Details: 📅 Date: November 2, 2024 ⏰ Time: 6:00 PM 🔗 Link for Contest: Community Weekly Contest Return - Contest No 1 P.S. Remember to fill out this form to secure your spot for our upcoming community classes and lectures. It’s your golden ticket to enriching experiences you won’t want to miss. 📚✨

mokrut 500k spot yekeral

bitget reward selazegaje mokrut just one click https://t.me/BitgetWallet_TGBot/BGW?startapp=sharetask-SPNPTCD7wpBmTF3 🎁❓ You’re invited to unlock a mystery gift! ❓🎁 First 1,000,000 only! Clicking this link guarantees your qualification. First come, first served, do not wait! Join me on Bitget Wallet Lite now!

#Q21 #leet_codeQ1249 Medium title. Minimum Remove to Make Valid Parentheses Given a string s of '(' , ')' and lowercase English characters. Your task is to remove the minimum number of parentheses ( '(' or ')', in any positions ) so that the resulting parentheses string is valid and return any valid string. Formally, a parentheses string is valid if and only if: It is the empty string, contains only lowercase characters, or It can be written as AB (A concatenated with B), where A and B are valid strings, or It can be written as (A), where A is a valid string. Example 1: Input: s = "lee(t(c)o)de)" Output: "lee(t(c)o)de" Explanation: "lee(t(co)de)" , "lee(t(c)ode)" would also be accepted. Example 2: Input: s = "a)b(c)d" Output: "ab(c)d" Example 3: Input: s = "))((" Output: "" Explanation: An empty string is also valid. Constraints: 1 <= s.length <= 105 s[i] is either '(' , ')', or lowercase English letter.

Selection sort
def selection_sort(arr):
    n = len(arr)
    for i in range(n - 1):
      
        # Assume the current position holds
        # the minimum element
        min_idx = i
        
        # Iterate through the unsorted portion
        # to find the actual minimum
        for j in range(i + 1, n):
            if arr[j] < arr[min_idx]:
              
                # Update min_idx if a smaller element is found
                min_idx = j
        
        # Move minimum element to its
        # correct position
        arr[i], arr[min_idx] = arr[min_idx], arr[i]

insertion sort
def insertionSort(arr):
    for i in range(1, len(arr)):
        key = arr[i]
        j = i - 1

        # Move elements of arr[0..i-1], that are
        # greater than key, to one position ahead
        # of their current position
        while j >= 0 and key < arr[j]:
            arr[j + 1] = arr[j]
            j -= 1
        arr[j + 1] = key

bubble sort
def bubbleSort(arr):
    n = len(arr)
    
    # Traverse through all array elements
    for i in range(n):
        swapped = False

        # Last i elements are already in place
        for j in range(0, n-i-1):

            # Traverse the array from 0 to n-i-1
            # Swap if the element found is greater
            # than the next element
            if arr[j] > arr[j+1]:
                arr[j], arr[j+1] = arr[j+1], arr[j]
                swapped = True
        if (swapped == False):
            break

this question is asked by amazon frequently in interview

#Q21 #leet_codeQ16 #3Sum_Closest Medium Given an integer array nums of length n and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solution. Example 1: Input: nums = [-1,2,1,-4], target = 1 Output: 2 Explanation: The sum that is closest to the target is 2. (-1 + 2 + 1 = 2). Example 2: Input: nums = [0,0,0], target = 1 Output: 0 Explanation: The sum that is closest to the target is 0. (0 + 0 + 0 = 0). Constraints: 3 <= nums.length <= 500 -1000 <= nums[i] <= 1000 -104 <= target <= 104

after solving 3 sum try to solve the next question

class Solution:
    def threeSum(self, nums: List[int]) -> List[List[int]]:
        nums = sorted(nums)
        list1 = []
        for i in range(len(nums)-1,-1,-1):
            j = i - 1
            left =0
            if (i>1 and i!=(len(nums)-1) and nums[i]==nums[i+1]):
                        continue
            while(j>-1 and left<=i-2 and j!=left):
                total = nums[left] + nums[i] + nums[j]
                if ( total)== 0:
                    list1.append([nums[left],nums[i],nums[j]])
                    left+=1
                    while(left<j and nums[left]==nums[left-1]):
                        left+=1
                elif total > 0:
                    j-=1
                else:
                    left+=1
        return list1

✨ Master Python Division: int(x / y) vs. x // y ✨ Ever wonder about the difference between int(x / y) and x // y in Python? Let’s break it down! 🧠👇 int(x / y): - Performs regular division first (x / y), giving a floating-point result. - Then, truncates the result to an integer using int(), removing the decimal part. - Example: - int(7 / 3) ➡️ 2 (since 7 / 3 ≈ 2.3333, truncates to 2). - int(-7 / 3) ➡️ -2 (since -7 / 3 ≈ -2.3333, truncates to -2). x // y (Floor Division): - Directly performs floor division, rounding down to the nearest integer. - Example: - 7 // 3 ➡️ 2 (largest integer ≤ 2.3333). - -7 // 3 ➡️ -3 (largest integer ≤ -2.3333). Key Differences: - Rounding: - int(x / y) truncates towards zero. - x // y rounds down towards negative infinity. - Negative numbers: - For positive results, both are the same. - For negative results, int(x / y) truncates, but x // y rounds down. Example with Negative Numbers: - int(-7 / 3) ➡️ -2 - -7 // 3 ➡️ -3

When working with division in Python, you might encounter two common ways to divide numbers: int(x / y) and x // y. Here’s how they differ: int(x / y): This performs regular division first (x / y), giving a floating-point result. It then converts that result to an integer using int(), which truncates the decimal part (rounds towards zero). Examples: int(7 / 3) results in 2 (as 7 / 3 equals approximately 2.3333). int(-7 / 3) results in -2 (as -7 / 3 equals approximately -2.3333). x // y (Floor Division): This directly performs floor division, which divides x by y and rounds down to the nearest integer (towards negative infinity). Examples: 7 // 3 results in 2 (the largest integer less than or equal to 2.3333). -7 // 3 results in -3 (the largest integer less than or equal to -2.3333). Key Differences: Rounding Direction: int(x / y) truncates towards zero. x // y rounds down towards negative infinity. Handling Negative Numbers: For positive numbers, both methods yield the same result. For negative numbers, int(x / y) truncates, while x // y rounds down. Example with Negative Numbers: int(-7 / 3) gives -2 (truncation). -7 // 3 gives -3 (floor division).

The difference between int(x / y) and x // y in Python lies in how they handle division and what they return as a result. ### 1. `int(x / y)`: - Operation: First performs regular (floating-point) division x / y, which gives a floating-point result. - Casting: The result is then explicitly converted to an integer using int(), which truncates the decimal part (rounds towards zero). - Result: The result is an integer value. Example:
   int(7 / 3)  # Result: 2
   int(-7 / 3)  # Result: -2
   
- 7 / 3 gives 2.3333..., and int() truncates it to 2. - -7 / 3 gives -2.3333..., and int() truncates it to -2. ### 2. `x // y` (Floor Division): - Operation: Performs floor division, which means it divides x by y and rounds down the result to the nearest integer towards negative infinity. - Result: Returns the largest integer less than or equal to the result of x / y. Example:
   7 // 3  # Result: 2
   -7 // 3  # Result: -3
   
- 7 // 3 gives 2 because it’s the largest integer less than or equal to 2.3333.... - -7 // 3 gives -3 because floor division rounds towards negative infinity, so -2.3333... becomes -3. ### Key Differences: 1. Rounding Direction: - int(x / y) truncates (rounds towards zero). - x // y uses floor division (rounds down towards negative infinity). 2. Handling Negative Numbers: - For positive numbers, both yield the same result. - For negative numbers, int(x / y) truncates towards zero, while x // y rounds down. ### Example with negative numbers:
int(-7 / 3)  # Result: -2
-7 // 3  # Result: -3
In this case, int(-7 / 3) gives -2 (truncating towards zero), while -7 // 3 gives -3 (rounding towards negative infinity).

https://t.me/+m835nLa3A0c2MjBk join our discussion group