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 240
订阅者
-124 小时
-37 天
-1730 天
帖子存档
1 240
"""
Given a binary array data, return the minimum number of swaps required to group all 1’s present in the array together in any place in the array.
Example 1:
Input: data = [1,0,1,0,1]
Output: 1
Explanation: There are 3 ways to group all 1's together:
[1,1,1,0,0] using 1 swap.
[0,1,1,1,0] using 2 swaps.
[0,0,1,1,1] using 1 swap.
The minimum is 1.
Example 2:
Input: data = [0,0,0,1,0]
Output: 0
Explanation: Since there is only one 1 in the array, no swaps are needed.
Example 3:
Input: data = [1,0,1,0,1,0,0,1,1,0,1]
Output: 3
Explanation: One possible solution that uses 3 swaps is [0,0,0,0,0,1,1,1,1,1,1].
Constraints:
1 <= data.length <= 10^5
data[i] is either 0 or 1.
"""20 12月 2024, 05:03
1 240
Report on my InterviewLiterally when I started my PC stacked🤯 and he was a peace guy he literally gave me 20 min after that I changed my PC with my friend and shared that. 1. After I shared my PC he introduced himself to me and also told me to share my screen asked me to go from tab desktop to check whether I shared my screen. Also he asked me to show my ID in front of the screen. 2. He dropped the question it was
leetcode 1198 Premium question (https://github.com/doocs/leetcode/blob/main/solution/1100-1199/1198.Find%20Smallest%20Common%20Element%20in%20All%20Rows/README_EN.md)3. I asked him to give me some time to understand the problem. When I saw the word strictly increasing I thought the question was Monotonic Stack but it wasn't. 4. After few silent minutes I think my adrelanine hormone just increased and the optimal one came to me but not the brute. 5. So I thought of a way to just sort the dictionary and make explain it as brute force. And literally it worked and asked me to Optimize it after I explained the time complexity. He also guided me on some other optimal related things like he told me to finish it inside the nested loop since it is strictly increasing matrix so I literally did that and explained as Optimal form and after I explained I implemented it quickly I started implementing while I was explaining the Brute one. 6. The technical was like that we finished it in 30min after that he gave 3 min and copy the code run and submit. He didn't told me whether it was accepted but I personally tested it on sharepad and it was correct for th given testcases. 7. After 5 min we started the Behavioural Interview he asked me 7 questions and agree on the policy the questions was literally same as the
G4 Interview Templateso I highly recommend to prepare on it. 8. After the interview I asked him about A2SV and other tech staff since he was Graduate student. And the interview entirely ended in 1:10 hr.
19 12月 2024, 23:29
1 240
Another Interview Question
▎Problem Statement
You are given a string s consisting only of the letters 'a' and 'b', and an integer k. You need to find the minimum number of character changes needed to obtain a substring of length ≥ k where all characters are the same.
Test Cases
Here are some test cases to illustrate the problem:
▎Test Case 1
• Input: s = "aabbaa", k = 3
• Output: 1
• Explanation: The substring "aaa" can be formed by changing one 'b' to 'a'.
▎Test Case 2
• Input: s = "ababab", k = 4
• Output: 2
• Explanation: To form "aaaa" or "bbbb", you need to change two characters (e.g., "aaab" or "bbba").
▎Test Case 3
• Input: s = "aaaaaa", k = 2
• Output: 0
19 12月 2024, 14:22
1 240
sorry for the minor error on the test cases , here is the updated
Question: Count Substrings with Same Start and End Character
Given a string s consisting only of lowercase English letters, your task is to find the number of substrings that start and end with the same character.
Examples:
Input: "abcba"
Output: 7
Explanation: The substrings are: "a", "b", "c", "b", "a", "bcb", and "aba".
Input: "abacada"
Output: 13
Explanation: The substrings are: "a", "b", "a", "c", "a", "d", "a", "aba", "aca", "ada", "abaca", "abada", and "abacad".
Input: "a"
Output: 1
Explanation: The only substring is "a".
Input: "zzzz"
Output: 10
Explanation: The substrings are: "z", "z", "z", "z", "zz", "zz", "zz", "zzz", "zzz", and "zzzz".
Challenge:
Write a function that takes a string as input and returns the total count of substrings that start and end with the same character.
19 12月 2024, 01:40
1 240
@zprogramming_bot or if u have any question u can ask me and if u have interviewed before please send us the question
18 12月 2024, 13:57
1 240
Question: Maximum Sum Score of an Array
You are given a 0-indexed integer array
nums of length n. The sum score of nums at an index i (where 0 <= i < n) is defined as the maximum of:
• The sum of the first i + 1 elements of nums.
• The sum of the last n - i elements of nums.
Your task is to return the maximum sum score of nums at any index.
▎Examples:
1. Input: nums = [4, 3, -2, 5]
Output: 10
Explanation:
• At index 0: max(4, 4 + 3 - 2 + 5) = max(4, 10) = 10.
• At index 1: max(4 + 3, 3 - 2 + 5) = max(7, 6) = 7.
• At index 2: max(4 + 3 - 2, -2 + 5) = max(5, 3) = 5.
• At index 3: max(4 + 3 - 2 + 5, 5) = max(10, 5) = 10.
• The maximum sum score of nums is 10.
2. Input: nums = [-3, -5]
Output: -3
Explanation:
• At index 0: max(-3, -3 - 5) = max(-3, -8) = -3.
• At index 1: max(-3 - 5, -5) = max(-8, -5) = -5.
• The maximum sum score of nums is -3.
▎Challenge:
Write a function maximumSumScore(nums) that takes an integer array as input and returns the maximum sum score.18 12月 2024, 13:19
1 240
Question: Count Substrings with Same Start and End Character
Given a string
s consisting only of lowercase English letters, your task is to find the number of substrings that start and end with the same character.
▎Examples:
1. Input: "abcba"
Output: 7
Explanation: The substrings are: "a", "b", "c", "b", "a", "bcb", and "abcba".
2. Input: "abacada"
Output: 9
Explanation: The substrings are: "a", "b", "a", "c", "a", "d", "aba", "aca", and "abaca".
3. Input: "a"
Output: 1
Explanation: The only substring is "a".
4. Input: "zzzz"
Output: 10
Explanation: All substrings start and end with 'z': "z", "z", "z", "z", "zz", "zz", "zz", "zz", "zzz", and "zzzz".
▎Challenge:
Write a function that takes a string as input and returns the total count of substrings that start and end with the same character.18 12月 2024, 13:18
1 240
▎💰 Problem 322: Coin Change
Problem Statement:
You are given an integer array
coins representing coins of different denominations and an integer amount representing a total amount of money.
Your task is to return the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1.
You may assume that you have an infinite number of each kind of coin.
▎Examples:
Example 1:
Input: coins = [1, 2, 5], amount = 11 Output: 3 Explanation: 11 can be made up with two 5's and one 1 (5 + 5 + 1).Example 2:
Input: coins = [2], amount = 3 Output: -1 Explanation: It is not possible to make up the amount 3 with only coin of denomination 2.Example 3:
Input: coins = [1], amount = 0 Output: 0 Explanation: No coins are needed to make up the amount 0.
17 12月 2024, 14:34
18 12月 2024, ~00:34
1 240
Question: Can You Make This String a Palindrome?
A palindrome is a string that reads the same forwards and backwards. Given a string, determine if it's possible to rearrange the characters to form a palindrome.
Examples:
1. Input:
"civic"
• Output: True
• Explanation: The string is already a palindrome.
2. Input: "ivicc"
• Output: True
• Explanation: Rearranging the characters can form the palindrome "civic".
3. Input: "hello"
• Output: False
• Explanation: No rearrangement can form a palindrome.
4. Input: "aabbcc"
• Output: True
• Explanation: Rearranging the characters can form the palindrome "abcba".
5. Input: "racecar"
• Output: True
• Explanation: The string is already a palindrome.
Challenge:
Write a function that takes a string as input and returns True if the string can be rearranged to form a palindrome, and False otherwise.17 12月 2024, 12:16
1 240
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?
02 12月 2024, 00:49
1 240
**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⁵ - -30 ≤ nums[i] ≤ 30 Can you solve it?
02 12月 2024, 00:48
02 12月 2024, ~00:49
1 240
**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 <= 105` - `-30 <= nums[i] <= 30` Can you solve it? 🧩
02 12月 2024, 00:47
02 12月 2024, ~00:47
