Leetcode with dani @zethioprograming Channel on Telegram

Leetcode with dani

@zethioprograming


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

Leetcode with dani (English)

Are you looking to improve your problem-solving skills and prepare for coding interviews? Look no further than 'Leetcode with dani' Telegram channel! Led by the username @zethioprograming, this channel is a hub for individuals who are eager to tackle Leetcode questions, learn new algorithms and data structures, and connect with other coding enthusiasts. Whether you are a beginner looking to sharpen your skills or an experienced coder seeking to stay ahead of the game, this channel is the perfect place for you. Join us today and embark on a journey towards becoming a more proficient coder. Let's tackle Leetcode questions together and take your coding skills to the next level!

Leetcode with dani

12 Jan, 21:27


check this ai it makes study easy https://app.youlearn.ai/learn/content/dc7773a6d5b3

Leetcode with dani

03 Jan, 11:31


can u solve it with out hash?and with only one loop and constant O(1) space?

Leetcode with dani

03 Jan, 11:24


share ur answer

Leetcode with dani

03 Jan, 11:23


409. Longest Palindrome
Given a string s which consists of lowercase or uppercase letters, return the length of the longest
palindrome
that can be built with those letters.

Letters are case sensitive, for example, "Aa" is not considered a palindrome.



Example 1:

Input: s = "abccccdd"
Output: 7
Explanation: One longest palindrome that can be built is "dccaccd", whose length is 7.
Example 2:

Input: s = "a"
Output: 1
Explanation: The longest palindrome that can be built is "a", whose length is 1.


Constraints:

1 <= s.length <= 2000
s consists of lowercase and/or uppercase English letters only.
Submit

Leetcode with dani

31 Dec, 21:09


🎄 Merry Christmas! 🎄
Wishing you all joy, love, and peace this holiday season.

As for the New Year… umm, is it appropriate to say "Happy New Year" now? 🤔
I mean, we’re rocking the Ethiopian calendar here! 🗓😎

Leetcode with dani

31 Dec, 15:21


The is the interview question I just had:

Given a binary array nums, return the maximum number of consecutive 1's in the array if you can flip at most one 0.

Example 1:
Input: nums = [1,0,1,1,0]
Output: 4
Explanation:
- If we flip the first zero, nums becomes [1,1,1,1,0] and we have 4 consecutive ones.
- If we flip the second zero, nums becomes [1,0,1,1,1] and we have 3 consecutive ones.
The max number of consecutive ones is 4.

max_cont= 4
max_count= 3
max_count =4
[1,0,1,1,0]

Example 2:
Input: nums = [1,0,1,1,0,1]
Output: 4
Explanation:
- If we flip the first zero, nums becomes [1,1,1,1,0,1] and we have 4 consecutive ones.
- If we flip the second zero, nums becomes [1,0,1,1,1,1] and we have 4 consecutive ones.
The max number of consecutive ones is 4.


Constraints:

1 <= nums.length <= 105
nums[i] is either 0 or 1.

Leetcode with dani

31 Dec, 10:40


todays interview

Leetcode with dani

31 Dec, 10:40


"""
Given a binary array nums, return the maximum number of consecutive 1's in the array.



Example 1:
Input: nums = [1,1,0,1,1,1]
Output: 3
Explanation: The first two digits or the last three digits are consecutive 1s. The maximum number of consecutive 1s is 3.

Example 2:
Input: nums = [1,0,1,1,0,1]
Output: 2


Constraints:

1 <= nums.length <= 105
nums[i] is either 0 or 1.

"""

Leetcode with dani

30 Dec, 09:29


today interview question

Leetcode with dani

30 Dec, 09:28


You are given a sorted array nums of size n and an integer target. 
Your task is to find the pair of numbers in the array whose sum is less than or equal to the target and has the largest possible sum.

Return the maximum sum of such a pair. If no valid pair exists, return -1.

Example 1:
Input: nums = [2, 3, 5, 8, 13], target = 10
Output: 10
l
[2, 3, 5, 8, 13],
r
[7,8 , 10]
Explanation: The pair (2, 8) has a sum of 10, which is the largest possible sum less than or equal to 10.

Example 2:
Input: nums = [1, 1, 1, 1], target = 1
Output: -1
Explanation: No pair has a sum less than or equal to 1.

Constraints:
1<=n<=10⁵
Nums is sorted in non-decreasing order.



def targetSum(nums , target):
left = 0
max_ = -1
right = len(nums)-1
while left < right:
sum = nums[left] + nums[right]
if sum == target:
return sum
elif sum > target:
right -=1
elif sum < target:
left += 1
max_ = max(max_,sum)
return max_

Leetcode with dani

29 Dec, 15:56


You are given a 0-indexed string s consisting of only lowercase English letters, and an integer count. A substring of s is said to be an equal count substring if, for each unique letter in the substring, it appears exactly count times in the substring.

Return the number of equal count substrings in s.

A substring is a contiguous non-empty sequence of characters within a string.



Example 1:

Input: s = "aaabcbbcc", count = 3
Output: 3
Explanation:
The substring that starts at index 0 and ends at index 2 is "aaa".
The letter 'a' in the substring appears exactly 3 times.
The substring that starts at index 3 and ends at index 8 is "bcbbcc".
The letters 'b' and 'c' in the substring appear exactly 3 times.
The substring that starts at index 0 and ends at index 8 is "aaabcbbcc".
The letters 'a', 'b', and 'c' in the substring appear exactly 3 times.
Example 2:

Input: s = "abcd", count = 2
Output: 0
Explanation:
The number of times each letter appears in s is less than count.
Therefore, no substrings in s are equal count substrings, so return 0.
Example 3:

Input: s = "a", count = 5
Output: 0
Explanation:
The number of times each letter appears in s is less than count.
Therefore, no substrings in s are equal count substrings, so return 0

Leetcode with dani

28 Dec, 20:13


another interview question

You are given a 0-indexed integer array nums.
Swaps of adjacent elements are able to be performed on nums.
A valid array meets the following conditions:
The largest element (any of the largest elements if there are multiple) is at the rightmost position in the array.
The smallest element (any of the smallest elements if there are multiple) is at the leftmost position in the array.
Return the minimum swaps required to make nums a valid array.

Example 1:
Input: nums = [3,4,5,5,3,1]
Output: 6
Explanation: Perform the following swaps:
- Swap 1: Swap the 3rd and 4th elements, nums is then [3,4,5,3,5,1].
- Swap 2: Swap the 4th and 5th elements, nums is then [3,4,5,3,1,5].
- Swap 3: Swap the 3rd and 4th elements, nums is then [3,4,5,1,3,5].
- Swap 4: Swap the 2nd and 3rd elements, nums is then [3,4,1,5,3,5].
- Swap 5: Swap the 1st and 2nd elements, nums is then [3,1,4,5,3,5].
- Swap 6: Swap the 0th and 1st elements, nums is then [1,3,4,5,3,5].
It can be shown that 6 swaps is the minimum swaps required to make a valid array.

Example 2:
Input: nums = [9]
Output: 0
Explanation: The array is already valid, so we return 0.




Constraints:
1 <= nums.length <= 10^5
1 <= nums[i] <= 10^5

Leetcode with dani

28 Dec, 19:39


i am not sure but i heard a news that the G6 result will be announced at the end of next week? did u get the info?

Leetcode with dani

28 Dec, 17:44


share urs in the comment section or in the group

Leetcode with dani

28 Dec, 17:40


https://leetcode.com/rewind/2024/

Leetcode with dani

28 Dec, 14:48


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: December 28, 2024
Time: 6:00 PM
🔗 Link for Contest: Community Weekly Contest - Contest No 7

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. 📚

Leetcode with dani

28 Dec, 06:16


if u want to submit the answer click me

Leetcode with dani

28 Dec, 06:13


it is not interview question

Leetcode with dani

28 Dec, 06:13


2461. Maximum Sum of Distinct Subarrays With Length K

You are given an integer array nums and an integer k. Find the maximum subarray sum of all the subarrays of nums that meet the following conditions:

The length of the subarray is k, and
All the elements of the subarray are distinct.
Return the maximum subarray sum of all the subarrays that meet the conditions. If no subarray meets the conditions, return 0.

A subarray is a contiguous non-empty sequence of elements within an array.



Example 1:

Input: nums = [1,5,4,2,9,9,9], k = 3
Output: 15
Explanation: The subarrays of nums with length 3 are:
- [1,5,4] which meets the requirements and has a sum of 10.
- [5,4,2] which meets the requirements and has a sum of 11.
- [4,2,9] which meets the requirements and has a sum of 15.
- [2,9,9] which does not meet the requirements because the element 9 is repeated.
- [9,9,9] which does not meet the requirements because the element 9 is repeated.
We return 15 because it is the maximum subarray sum of all the subarrays that meet the conditions
Example 2:

Input: nums = [4,4,4], k = 3
Output: 0
Explanation: The subarrays of nums with length 3 are:
- [4,4,4] which does not meet the requirements because the element 4 is repeated.
We return 0 because no subarrays meet the conditions.


Constraints:

1 <= k <= nums.length <= 105
1 <= nums[i] <= 105

Leetcode with dani

27 Dec, 17:56


Todays another interview questions

Leetcode with dani

27 Dec, 17:56


"""

Question Description
Given an input string s, reverse the order of the words.

A word is defined as a sequence of non-space characters. The words in s will be separated by at least one space.

Return a string of the words in reverse order concatenated by a single space.

Note that s may contain leading or trailing spaces or multiple spaces between two words.
The returned string should only have a single space separating the words. Do not include any extra spaces.



Example 1:

Input: s = "the sky is blue"
Output: "blue is sky the"
Example 2:

Input: s = " hello world "
Output: "world hello"
Explanation: Your reversed string should not contain leading or trailing spaces.
Example 3:

Input: s = "a good example"
Output: "example good a"
Explanation: You need to reduce multiple spaces between two words to a single space in the reversed string.


Constraints:

1 <= s.length <= 104
s contains English letters (upper-case and lower-case), digits, and spaces ' '.
There is at least one word in s.


"a good example"
["a","good","example"]
L R


[example,"good","a"]


"""

#will s will split
#variables left->0 rght ->len(splited)-1
#will have a while l<L left+=1 righ-=1


def revercing_word(s):
words=[]
for word in s.split(" "):
if word:
words.append(word)

left=0
right=len(words)-1


while left<right:
words[left],words[right]= words[right],words[left]
left+=1
right-=1

return " ".join(words)
print(revercing_word("hello world"))

Leetcode with dani

27 Dec, 17:54


Todays interview question

A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.

Given a string s, return true if it is a palindrome, or false otherwise.



Example 1:

Input: s = "A man, a plan, a canal: Panama"
Output: true
Explanation: "amanaplanacanalpanama" is a palindrome.
Example 2:

Input: s = "race a car"
Output: false
Explanation: "raceacar" is not a palindrome.
Example 3:

Input: s = " "
Output: true
Explanation: s is an empty string "" after removing non-alphanumeric characters.
Since an empty string reads the same forward and backward, it is a palindrome.


Constraints:

1 <= s.length <= 2 * 105
s consists only of printable ASCII characters.

Leetcode with dani

27 Dec, 05:28


Today's Interview Question
You are given a string s, which contains stars *.

In one operation, you can:

Choose a star in s.
Remove the closest non-star character to its left, as well as remove the star itself.
Return the string after all stars have been removed.

Note:

The input will be generated such that the operation is always possible.
It can be shown that the resulting string will always be unique.


Example 1:
Input: s = "leet**cod*e"
Output: "lecoe"
Explanation: Performing the removals from left to right:
- The closest character to the 1st star is 't' in "leet**cod*e". s becomes "lee*cod*e".
- The closest character to the 2nd star is 'e' in "lee*cod*e". s becomes "lecod*e".
- The closest character to the 3rd star is 'd' in "lecod*e". s becomes "lecoe".
There are no more stars, so we return "lecoe".

Example 2:
Input: s = "erase*****"
Output: ""
Explanation: The entire string is removed, so we return an empty string.

Constraints:

1 <= s.length <= 10**5
s consists of lowercase English letters and stars *.
The operation above can be performed on s.
```
def fun(s):
    stack = []
    for c in s:
        if c != "*":
            stack.append(c)
        else:
            stack.pop()
    return "".join(stack)
print(fun("erase*****"))

`

Leetcode with dani

25 Dec, 18:33


Iterating through a string and appending to an empty string in Python has O(n²) time complexity because strings are immutable, and each append involves copying the entire string so far.

Optimized Approach: Use a list to collect characters and join them at the end:

result = []
for char in string:
result.append(char)
final_string = ''.join(result)

This reduces the time complexity to O(n).

Leetcode with dani

24 Dec, 16:43


https://leetcode.com/problems/adding-spaces-to-a-string/

Leetcode with dani

24 Dec, 16:28


are u ready to do another interview question?

Leetcode with dani

23 Dec, 17:17


2760. Longest Even Odd Subarray With Threshold

You are given a 0-indexed integer array nums and an integer threshold.

Find the length of the longest subarray of nums starting at index l and ending at index r (0 <= l <= r < nums.length) that satisfies the following conditions:

nums[l] % 2 == 0
For all indices i in the range [l, r - 1], nums[i] % 2 != nums[i + 1] % 2
For all indices i in the range [l, r], nums[i] <= threshold
Return an integer denoting the length of the longest such subarray.

Note: A subarray is a contiguous non-empty sequence of elements within an array.



Example 1:

Input: nums = [3,2,5,4], threshold = 5
Output: 3
Explanation: In this example, we can select the subarray that starts at l = 1 and ends at r = 3 => [2,5,4]. This subarray satisfies the conditions.
Hence, the answer is the length of the subarray, 3. We can show that 3 is the maximum possible achievable length.
Example 2:

Input: nums = [1,2], threshold = 2
Output: 1
Explanation: In this example, we can select the subarray that starts at l = 1 and ends at r = 1 => [2].
It satisfies all the conditions and we can show that 1 is the maximum possible achievable length.
Example 3:

Input: nums = [2,3,4,5], threshold = 4
Output: 3
Explanation: In this example, we can select the subarray that starts at l = 0 and ends at r = 2 => [2,3,4].
It satisfies all the conditions.
Hence, the answer is the length of the subarray, 3. We can show that 3 is the maximum possible achievable length.


Constraints:

1 <= nums.length <= 100
1 <= nums[i] <= 100
1 <= threshold <= 100
you can test on the leetcode

Leetcode with dani

22 Dec, 17:51


if u want the answers for the questions, ask in the comment section

Leetcode with dani

22 Dec, 17:35



"""
Given an array of integer arrays arrays where each arrays[i] is sorted in strictly increasing order,
return an integer array representing the longest common subsequence among all the arrays.
A subsequence is a sequence that can be derived from another sequence by deleting some elements
(possibly none) without changing the order of the remaining elements.

Example 1:
Input: arrays = [[1,3,4],
[1,4,7,9]]
Output: [1,4]
Explanation: The longest common subsequence in the two arrays is [1,4].

Example 2:
Input: arrays = [[2,3,6,8],
[1,2,3,5,6,7,10],
[2,3,4,6,9]]
Output: [2,3,6]
Explanation: The longest common subsequence in all three arrays is [2,3,6].

Example 3:
Input: arrays = [[1,2,3,4,5],
[6,7,8]]
Output: []
Explanation: There is no common subsequence between the two arrays.
"""

Leetcode with dani

22 Dec, 08:30


Join our group and let's build a community of tech friends. The best thing about networking is that you might meet someone who shares a job opportunity with you, helping you land your first job. That friend could support you on your tech journey, or you could be that friend for someone else. I also want to be part of this group, so feel free to connect with me. Please Share to ur friends
https://t.me/+m835nLa3A0c2MjBk

Leetcode with dani

22 Dec, 08:26


Leetcode with dani pinned «https://t.me/+m835nLa3A0c2MjBk join our discussion group»

Leetcode with dani

22 Dec, 07:54


I am also practicing for the A2SV interview, so please wish me good luck😁

Leetcode with dani

22 Dec, 06:44


Given an integer array nums of 2n integers, group these integers into n pairs (a1, b1), (a2, b2), ..., (an, bn) such that the sum of min(ai, bi) for all i is maximized.
Return the maximized sum.

Example 1:

Input: nums = [1,4,3,2]
Output: 4

Explanation: All possible pairings (ignoring the ordering of elements) are:
1. (1, 4), (2, 3) -> min(1, 4) + min(2, 3) = 1 + 2 = 3
2. (1, 3), (2, 4) -> min(1, 3) + min(2, 4) = 1 + 2 = 3
3. (1, 2), (3, 4) -> min(1, 2) + min(3, 4) = 1 + 3 = 4
So the maximum possible sum is 4.
Example 2:

Input: nums = [6,2,6,5,1,2]
Output: 9
Explanation: The optimal pairing is (2, 1), (2, 5), (6, 6). min(2, 1) + min(2, 5) + min(6, 6) = 1 + 2 + 6 = 9.
1 2 2 5 6 6


Constraints:

1 <= n <= 104
nums.length == 2 * n
-104 <= nums[i] <= 104

Leetcode with dani

02 Dec, 05:50


Leetcode

Leetcode with dani

02 Dec, 05:49



238. Product of Array Except Self
Difficulty: Medium

Problem:
Given an integer array nums, return an array answer such that answer[i] is the product of all elements of nums except nums[i].

Conditions:
- The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.
- Your algorithm must run in O(n) time and must not use the division operation.

Examples:
Input: nums = [1,2,3,4]
Output: [24,12,8,6]

Input: nums = [-1,1,0,-3,3]
Output: [0,0,9,0,0]

Constraints:
2 <= nums.length <= 10^5
-30 <= nums[i] <= 30

Can you solve it?

Leetcode with dani

21 Nov, 14:23


🎯 Problem of the Day: Sort Colors

Problem Description
You are given an array nums with \( n \) objects colored red, white, or blue. Sort the array in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue.
- Represent the colors using integers:
- 0 → Red
- 1 → White
- 2 → Blue

⚠️ Note: You must not use the library's sort function.

---

Example 1
Input:
nums = [2,0,2,1,1,0]

Output:
[0,0,1,1,2,2]


Example 2
Input:
nums = [2,0,1]

Output:
[0,1,2]


---

📝 Practice Questions for A2SV Preparation
1. Core Problem:
- Solve LeetCode 75: Sort Colors () using Dutch National Flag Algorithm for \( O(n) \) time complexity.

2. Related Problems:
- LeetCode 215 : Kth Largest Element in an Array
- LeetCode 347 : Top K Frequent Elements
- LeetCode 56 : Merge Intervals

3. Challenge Problem:
- LeetCode 88: Merge Sorted Array

---

💡 Tip: Use a two-pointer or three-pointer approach to keep track of boundaries for the different colors! Try to optimize your solution to \( O(n) \) in both time and space.

🧠 Share your solution and discuss your approach with the community! 🌟

Leetcode with dani

21 Nov, 12:45


Hello G6 In-Person Education Applicants,

As you gear up for your interviews, we want to inform you about the key topics to focus on. These are the areas that will be covered during the interview:

- Sorting
- Two Pointers
- Sliding Window
- Prefix Sum
- Stacks and Queues

Best of luck with your preparation! Stay confident and ready to showcase your skills.

Leetcode with dani

19 Nov, 20:04


ወንድማችን ተማሪ አዲሱ አገዘ የአ.አ.ዩ /CNCS የChemistry ዲፓርትመንት ተማሪ ሲሆን በድንገተኛ የጤና እክል ምክንያት በጥቁር አንበሳ ስፔሻላይዝድ ሆስፒታል የህክምና ክትትል እየተደረገለት ይገኛል። ሆኖም ግን ለህክምናና ለአንዳንድ ወጪዎች የሚሆነውን ገንዘብ መሸፈን ስላልተቻለ ለእርዳታ ሲባል ባለ3 ጥምር የባንክ አካውንት ተከፍቶ አቅም የፈቀደውን እና ልብ የወደደውን ገቢ በማድረግ የእርዳታ እጃችሁን እንድትዘረጉልን ስንል በፈጣሪ ስም እንጠይቃለን።

ድር ቢያብር...

1000660602899 Surafel and Lud and Belete (CBE)

ለመረጃ: 0928750009

Leetcode with dani

15 Nov, 20:06


FOR A2SV

Leetcode with dani

14 Nov, 12:03


Applications are Open for A2SV G6 Education!

The time has come for A2SV to welcome new members! We’re looking for team-oriented individuals with a never-give-up mentality, ready to drive tech excellence and solve impactful challenges.

📅 Application opens: November 14, 2024
📅 Deadline: November 20, 2024, at 11:59 PM EAT

🎓 Eligibility

Open to current students from Addis Ababa University (AAU), Addis Ababa Science and Technology University (AASTU), and Adama Science and Technology University (ASTU). If you're not from these schools or have already graduated, stay tuned for future remote applications!

🔍 Requirements

- Familiarity with at least one programming language
- Experience with platforms like LeetCode or Codeforces
- Completed at least 40 problems on LeetCode or Codeforces

🤖 Selection Process

- First Round Filtering: Initial application review
- Technical & Behavioral Interviews: For selected candidates, to assess skills and fit for the program

⌛️ Don’t wait! Start your application early to ensure a standout submission. 🎯

🔗 Apply now: link

#A2SV #TechEducation #EmpoweringAfrica #ApplyNow

Leetcode with dani

09 Nov, 11:32


We move to our next unmarked number 5 and mark all multiples of 5 and are greater than or equal to the square of it.

Leetcode with dani

09 Nov, 11:32


Sieve of Eratosthenes

Given a number n, print all primes smaller than or equal to n. It is also given that n is a small number.

Example:

Input : n =10
Output : 2 3 5 7


Input : n = 20
Output: 2 3 5 7 11 13 17 19

The sieve of Eratosthenes is one of the most efficient ways to find all primes smaller than n when n is smaller than 10 million or so.

Following is the algorithm to find all the prime numbers less than or equal to a given integer n by the Eratosthene’s method:
When the algorithm terminates, all the numbers in the list that are not marked are prime.

Explanation with Example:

Leetcode with dani

09 Nov, 11:32


Let us take an example when n = 100. So, we need to print all prime numbers smaller than or equal to 100.


We create a list of all numbers from 2 to 100.

Leetcode with dani

09 Nov, 11:32


According to the algorithm we will mark all the numbers which are divisible by 2 and are greater than or equal to the square of it.

Leetcode with dani

09 Nov, 11:32


Now we move to our next unmarked number 3 and mark all the numbers which are multiples of 3 and are greater than or equal to the square of it.

Leetcode with dani

09 Nov, 11:32


So, the prime numbers are the unmarked ones: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89 and 97.

Leetcode with dani

09 Nov, 11:32


We continue this process, and our final table will look like below:

Leetcode with dani

08 Nov, 06:24


Given a number n, print all primes smaller than or equal to n. It is also given that n is a small number.

Example:

Input : n =10
Output : 2 3 5 7


Input : n = 20
Output: 2 3 5 7 11 13 17 19

Leetcode with dani

06 Nov, 15:04


iphone 11 emigeza sw kale contact me 0936464894 25,500birr

Leetcode with dani

05 Nov, 18:31


share ur answer in the comment section , i will check it

Leetcode with dani

05 Nov, 12:20


🏆 LeetCode 490. The Maze (Premium) 🏆

There's a ball in a maze with:
- Empty spaces (0) and walls (1).

The ball can roll in any direction:
- Up, down, left, or right 🌐

But here's the catch:
- It won't stop until it hits a wall! 🚧
- Once it stops, it can choose another direction to roll.

### Task 🎯
Given:
- An m x n maze
- The ball's starting position and a destination

Determine:
- Can the ball stop at the destination?
- If yes, return true. Otherwise, return false.

📝 Assumption: All borders of the maze are walls.

---

### Examples 🔍

Example 1:

Input: 
maze = [
[0,0,1,0,0],
[0,0,0,0,0],
[0,0,0,1,0],
[1,1,0,1,1],
[0,0,0,0,0]
],
start = [0,4],
destination = [4,4]

Output: true

Explanation: One possible path: left ➡️ down ➡️ left ➡️ down ➡️ right ➡️ down ➡️ right 🎯

---

Example 2:

Input:
maze = [
[0,0,1,0,0],
[0,0,0,0,0],
[0,0,0,1,0],
[1,1,0,1,1],
[0,0,0,0,0]
],
start = [0,4],
destination = [3,2]

Output: false

Explanation: The ball can pass through the destination, but it cannot stop there.

---

Example 3:

Input:
maze = [
[0,0,0,0,0],
[1,1,0,0,1],
[0,0,0,0,0],
[0,1,0,0,1],
[0,1,0,0,0]
],
start = [4,3],
destination = [0,1]

Output: false


---

### Constraints 📏
- Maze Dimensions: 1 ≤ m, n ≤ 100
- Cells contain only 0 (empty) or 1 (wall).
- Start and destination are in empty spaces and won’t initially overlap.

Can you solve it? 🤔

Leetcode with dani

02 Nov, 12:11


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. 📚

Leetcode with dani

28 Oct, 18:38


https://a2sv.org/

Leetcode with dani

21 Oct, 06:10


#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.

Leetcode with dani

18 Oct, 07:43


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]

Leetcode with dani

18 Oct, 07:42


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

Leetcode with dani

18 Oct, 07:42


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

Leetcode with dani

18 Oct, 07:30


this question is asked by amazon in interviews frequently

https://leetcode.com/problems/the-kth-factor-of-n/?envType=study-plan-v2&envId=amazon-spring-23-high-frequency

Leetcode with dani

18 Oct, 04:57


#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

Leetcode with dani

18 Oct, 04:55


after solving 3 sum try to solve the next question

Leetcode with dani

18 Oct, 04:53


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

Leetcode with dani

18 Oct, 04:51


https://youtu.be/jzZsG8n2R9A?si=s8jIL0Yg1LiGfwoC

Leetcode with dani

17 Oct, 14:21


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

Leetcode with dani

17 Oct, 13:26


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

Leetcode with dani

17 Oct, 12:36


did you solve this problem?

Leetcode with dani

16 Oct, 17:09


In my opinion, if you're preparing for an interview and have no enough time left, it’s best not to spend more than 45 minutes on a single problem. Instead, I believe you should focus on understanding different patterns and concepts. This approach can help you become more versatile and better equipped to tackle various questions during the interview. what do you think?

Leetcode with dani

16 Oct, 17:02


#Q20 #leet_codeQ15 Medium title. 3Sum
Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.

Notice that the solution set must not contain duplicate triplets.



Example 1:

Input: nums = [-1,0,1,2,-1,-4]
Output: [[-1,-1,2],[-1,0,1]]
Explanation:
nums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0.
nums[1] + nums[2] + nums[4] = 0 + 1 + (-1) = 0.
nums[0] + nums[3] + nums[4] = (-1) + 2 + (-1) = 0.
The distinct triplets are [-1,0,1] and [-1,-1,2].
Notice that the order of the output and the order of the triplets does not matter.
Example 2:

Input: nums = [0,1,1]
Output: []
Explanation: The only possible triplet does not sum up to 0.
Example 3:

Input: nums = [0,0,0]
Output: [[0,0,0]]
Explanation: The only possible triplet sums up to 0.

Leetcode with dani

06 Sep, 23:45


🚀 Explore Palindrome Challenges with the Two-Pointer Technique!🧑‍💻

Palindromes are a classic problem type that can be efficiently tackled using the two-pointer technique. Whether you're just starting or looking to refine your skills, these questions will help you master this approach. Check out these palindrome problems:

1.Valid Palindrome
🔗 [Link](https://leetcode.com/problems/valid-palindrome/)
Description: Determine if a string is a palindrome, considering only alphanumeric characters and ignoring cases.

2. Valid Palindrome II
🔗 [Link](https://leetcode.com/problems/valid-palindrome-ii/)
Description: Can the string become a palindrome by deleting just one character?

3. Palindrome Linked List
🔗 [Link](https://leetcode.com/problems/palindrome-linked-list/)
Description: Check if a singly linked list is a palindrome using two pointers and a bit of list manipulation.

4. Longest Palindromic Substring
🔗 [Link](https://leetcode.com/problems/longest-palindromic-substring/)
Description: Find the longest palindromic substring in a given string, with pointers expanding from each character.

5. Palindromic Substrings
🔗 [Link](https://leetcode.com/problems/palindromic-substrings/)
Description: Count how many palindromic substrings are present in the string using two pointers.

6. Shortest Palindrome.
🔗 [Link](https://leetcode.com/problems/shortest-palindrome/)
Description: Find the shortest palindrome by adding characters to the start of the string.

7. Palindrome Partitioning
🔗 [Link](https://leetcode.com/problems/palindrome-partitioning/)
Description: Partition a string into all possible palindromic substrings.

8. Palindrome Pairs
🔗 [Link](https://leetcode.com/problems/palindrome-pairs/)
Description: Given a list of words, find all pairs of distinct indices that form palindromes.

Ready to boost your problem-solving skills? Dive into these problems, practice your two-pointer technique, and ace those palindrome challenges! 💥

Happy Coding! 💻💡

Leetcode with dani

02 Sep, 08:24


▎1. 3Sum

def threeSum(nums):
    nums.sort()
    result = []
    for i in range(len(nums) - 2):
        if i > 0 and nums[i] == nums[i - 1]:
            continue
        left, right = i + 1, len(nums) - 1
        while left < right:
            total = nums[i] + nums[left] + nums[right]
            if total < 0:
                left += 1
            elif total > 0:
                right -= 1
            else:
                result.append([nums[i], nums[left], nums[right]])
                while left < right and nums[left] == nums[left + 1]:
                    left += 1
                while left < right and nums[right] == nums[right - 1]:
                    right -= 1
                left += 1
                right -= 1
    return result



▎2. Minimum Window Substring

from collections import Counter

def minWindow(s, t):
    if not t or not s:
        return ""
   
    dict_t = Counter(t)
    required = len(dict_t)
   
    l, r = 0, 0
    formed = 0
    window_counts = {}
   
    ans = float("inf"), None, None
   
    while r < len(s):
        character = s[r]
        window_counts[character] = window_counts.get(character, 0) + 1
       
        if character in dict_t and window_counts[character] == dict_t[character]:
            formed += 1
       
        while l <= r and formed == required:
            character = s[l]
           
            if r - l + 1 < ans[0]:
                ans = (r - l + 1, l, r)
           
            window_counts[character] -= 1
            if character in dict_t and window_counts[character] < dict_t[character]:
                formed -= 1
           
            l += 1
       
        r += 1
   
    return "" if ans[0] == float("inf") else s[ans[1]: ans[2] + 1]



▎3. Fruit Into Baskets

def totalFruits(fruits):
    left, right = 0, 0
    basket = {}
    max_fruits = 0
   
    while right < len(fruits):
        basket[fruits[right]] = basket.get(fruits[right], 0) + 1
       
        while len(basket) > 2:
            basket[fruits[left]] -= 1
            if basket[fruits[left]] == 0:
                del basket[fruits[left]]
            left += 1
       
        max_fruits = max(max_fruits, right - left + 1)
        right += 1
   
    return max_fruits

Leetcode with dani

02 Sep, 08:20


1. 3Sum (Hard) 
   Answer: The solution involves sorting the array and using a two-pointer technique to find triplets that sum to zero. The time complexity is O(n^2).


2. Minimum Window Substring (Hard) 
   Answer: Use a sliding window approach to maintain a count of characters and expand/shrink the window until the minimum substring is found. The time complexity is O(n).

3. Fruit Into Baskets (Easy) 
   Answer: Utilize a sliding window to track the types of fruits and their counts, ensuring you only have two types at any time. The maximum length of the window gives the answer. The time complexity is O(n).

Leetcode with dani

31 Aug, 10:40


Understanding the constraints, time complexity is key to solving LeetCode problems effectively. If you find these concepts confusing, don’t worry , you’re not alone!.

this might help you to undestand the constraints

Leetcode with dani

30 Aug, 07:39


3. Fruit Into Baskets (Easy)
Description: You are visiting a farm and have a basket that can hold at most two types of fruits. You want to maximize the number of fruits you collect. Given an array of integers representing the types of fruits in a row, find the maximum number of fruits you can collect in one basket.
- Example: For input [1,2,1], the maximum number of fruits collected is 3.

Leetcode with dani

30 Aug, 07:38


2. Minimum Window Substring (Hard)
Description: Given two strings s and t, return the minimum window substring of s such that every character in t (including duplicates) is included in the window. If there is no such substring, return an empty string.
- Example: For s = "ADOBECODEBANC" and t = "ABC", the minimum window is "BANC".