LeetCode POTD š«: Description: AĀ happy stringĀ is a string that: -> consists only of letters of the setĀ ['a', 'b', 'c']. -> s[i] != s[i + 1]Ā for all values ofĀ iĀ fromĀ 1Ā toĀ s.length - 1Ā (string is 1-indexed). For example, stringsĀ "abc", "ac", "b"Ā andĀ "abcbabcbcb"Ā are all happy strings and stringsĀ "aa", "baa"Ā andĀ "ababbc"Ā are not happy strings. Given two integersĀ nĀ andĀ k, consider a list of all happy strings of lengthĀ nĀ sorted in lexicographical order. ReturnĀ the kth stringĀ of this list or return anĀ empty stringĀ if there are less thanĀ kĀ happy strings of lengthĀ n. Here's my solution: https://lnkd.in/gEe77wac #Python #DSA #Leetcode #DailyChallenge #Recursion
LeetCode Daily Challenge: Happy Strings
More Relevant Posts
-
Day 67 of 365 Days of code the infamous brainrot number Qn 1) Reorder list You are given the head of a singly linked-list. The positions of a linked list ofĀ length = 7Ā for example, can intially be represented as: [0, 1, 2, 3, 4, 5, 6] Reorder the nodes of the linked list to be in the following order: [0, 6, 1, 5, 2, 4, 3] Notice that in the general case for a list ofĀ length = nĀ the nodes are reordered to be in the following order: [0, n-1, 1, n-2, 2, n-3, ...] You may not modify the values in the list's nodes, but instead you must reorder the nodes themselves. approach: use 5 pointers(scary :")) #365daysOfCode #NeetCodeĀ #leetcodeĀ #DSAĀ #python #LeetCode #ProblemSolvingĀ #Algorithms #365dayschallenge
To view or add a comment, sign in
-
-
LeetCode POTD š«: Trying to be consistent with POTDs š« Description: You are given two strings,Ā str1Ā andĀ str2, of lengthsĀ nĀ andĀ m, respectively. A stringĀ wordĀ of lengthĀ n + m - 1Ā is defined to beĀ generatedĀ byĀ str1Ā andĀ str2Ā if it satisfies the following conditions forĀ eachĀ indexĀ 0 <= i <= n - 1: -> IfĀ str1[i] == 'T', theĀ substringĀ ofĀ wordĀ with sizeĀ mĀ starting at indexĀ iĀ isĀ equalĀ toĀ str2, i.e.,Ā word[i..(i + m - 1)] == str2. -> IfĀ str1[i] == 'F', theĀ substringĀ ofĀ wordĀ with sizeĀ mĀ starting at indexĀ iĀ isĀ not equalĀ toĀ str2, i.e.,Ā word[i..(i + m - 1)] != str2. Return theĀ lexicographically smallestĀ possible string that can beĀ generatedĀ byĀ str1Ā andĀ str2. If no string can be generated, return an empty stringĀ "". Here's my solution: https://lnkd.in/g6B2-GWz #Python #DSA #Leetcode #DailyChallenge
To view or add a comment, sign in
-
-
š #100DaysOfCode ā Day 52 š Problem: Sort Colors (LeetCode 75) š” Problem Idea: You are given an array containing only 0s, 1s, and 2s, representing three colors. The task is to sort the array in-place so that all 0s come first, then 1s, and then 2s. ā” Key Insight: Instead of using a sorting algorithm, we can solve this in one pass using three pointers. We maintain three regions: Left pointer ā position for next 0 Right pointer ā position for next 2 Current pointer (i) ā traverses the array šÆ Approach (Dutch National Flag Algorithm): If element is 0 ā swap with left, move both left and i If element is 1 ā just move i If element is 2 ā swap with right, decrease right š Complexity: Time Complexity: O(n) Space Complexity: O(1) (in-place sorting) ā Efficient because the array is processed only once. š Learning: This problem is a great example of how pointer techniques can optimize sorting problems without using built-in sort functions. #DSA #LeetCode #Python #CodingJourney #ProblemSolving #Algorithms #100DaysOfCode #LinkedInLearning
To view or add a comment, sign in
-
-
LeetCode Problem 3070: "Count submatrices with top left element and sum less than k": You are given aĀ 0-indexedĀ integer matrixĀ gridĀ and an integerĀ k. ReturnĀ theĀ numberĀ ofĀ submatricesĀ that contain the top-left element of theĀ grid,Ā and have a sum less than or equal toĀ k. Approach: use Prefix sum to calculate the total value of submatrix including the top left element upto a given cell. This approach is optimal and straightforward. #Python #DSA #LeetCode #ProblemSolving #CompetitiveProgramming #DailyCoding
To view or add a comment, sign in
-
-
š DSA Practice ā Check if a String is a Palindrome Today I worked on a fundamental string challenge: Determining whether a given string is a palindrome. š Problem Statement: Given a string s, verify if it reads the same backward as forward. A palindrome is a sequence that is identical even when its order is reversed. š§ My Approach: 1ļøā£ Clean the Data: Convert the string to a uniform case (lowercase) to ensure the comparison is case-insensitive. 2ļøā£ Reverse and Compare: Use Pythonās powerful slicing technique s[::-1] to create a reversed version of the string. 3ļøā£ Verification: Compare the original string with the reversed one. If they match, it's a palindrome; otherwise, it's not. āļø Example: Input: "madam" ā Output: True Input: "hello" ā Output: False š Complexity: Time Complexity: $O(n)$ (where $n$ is the length of the string, as we traverse it to reverse). Auxiliary Space: $O(n)$ (to store the reversed version of the string). š» Language Used: Python This problem is a great way to practice string slicing and understanding how data is stored and compared in memory. It's a stepping stone toward more complex "Two-Pointer" string problems! #DSA #Python #CodingPractice #ProblemSolving #Strings #Palindrome #LearningInPublic
To view or add a comment, sign in
-
-
LeetCode POTD š«: Description: A stringĀ originalTextĀ is encoded using aĀ slanted transposition cipherĀ to a stringĀ encodedTextĀ with the help of a matrix having aĀ fixed number of rowsĀ rows. originalTextĀ is placed first in a top-left to bottom-right manner. encodedTextĀ is then formed by appending all characters of the matrix in a row-wise fashion. Given the encoded stringĀ encodedTextĀ and number of rowsĀ rows, returnĀ the original stringĀ originalText. Note:Ā originalTextĀ does notĀ have any trailing spacesĀ ' '. The test cases are generated such that there is only one possibleĀ originalText. Here's my solution: https://lnkd.in/g2EMmfzE #Python #DSA #Leetcode #DailyChallenge
To view or add a comment, sign in
-
-
š Comparing Performance After Optimization in django-mariadb-vector Since version v0.2.0, the 'django-mariadb-vector'Ā library includes several optimization options. Here are the results from performance tests. šBenefits 'orjson' vs 'json' šø Up toĀ ~20ĆĀ fasterĀ compared to the standard `json` library on generate vector data šø Up toĀ ~8ĆĀ fasterĀ compared to the standard `json` library on response vector data šBenefits of 'binary' on response vector data šø Up toĀ ~16Ć fasterĀ compared to the standard `json` library šø AboutĀ ~2Ć fasterĀ compared to `orjson` š https://lnkd.in/d82cnBMn ā ļø Note: Performance was measured using 20,000 iterations (3 runs) with randomly generated vectors of dimension 3072. #django #python #mariadb #vector #django-mariadb-vector #optimization #json #orjson #rust
To view or add a comment, sign in
-
-
Third PR merged, a feature addition to skore's ImpurityDecreaseDisplay. :probabl. PR: https://lnkd.in/evSrq9GD The problem: ImpurityDecreaseDisplay.frame() returned raw per-split rows with no way to aggregate across them. Other display classes in the suite already had this. ImpurityDecreaseDisplay was the odd one out. Added an aggregate parameter. When set, per-split rows collapse into importance_mean and importance_std, replacing the split column. Also made _plot_matplotlib pass aggregate=None explicitly to keep plotting behavior unambiguous. Opened this as a draft initially because I wasn't sure how aggregation should behave for the comparison-cross-validation report type. Left the question in the PR description, the maintainers clarified, I updated, it shipped. #opensource #python #skore #scikitlearn #machinelearning
To view or add a comment, sign in
-
-
š Day 39/100 ā LeetCode Challenge Todayās problem: 406. Queue Reconstruction by Height This problem focuses on applying a Greedy approach with sorting to reconstruct a queue based on height and positional constraints. š Key Insight: Sort people by height in descending order and k value in ascending order, then insert each person at their respective index. š” What I learned: Importance of sorting strategy in greedy problems How insertion at a specific index can maintain constraints Thinking from the perspective of "who affects whom" (taller vs shorter) š§ Approach: Sort the array ā (-height, k) Insert each person at index k š» Code (Python): class Solution: def reconstructQueue(self, people): people.sort(key=lambda x: (-x[0], x[1])) queue = [] for p in people: queue.insert(p[1], p) return queue ā±ļø Time Complexity: O(n²) Consistency is the key ā showing up every day and improving step by step. #Day39 #LeetCode #100DaysOfCode #DSA #Python #CodingChallenge #GreedyAlgorithm #SoftwareDevelopment
To view or add a comment, sign in
-
-
š Day 75 of #100DaysOfCode š„ LeetCode 179 ā Largest Number š” Problem: Given a list of non-negative integers, arrange them such that they form the largest possible number. š§ Key Insight: Normal sorting won't work here ā We need a custom comparator based on string concatenation. š Compare: - ""a + b"" vs ""b + a"" - Whichever gives a larger value should come first. āļø Approach: 1. Convert numbers to strings 2. Sort using custom comparison logic 3. Join the result 4. Handle edge case (like "[0,0] ā "0"") ā” Complexity: - Time: O(n log n) - Space: O(n) šÆ Result: ā Accepted ā” Runtime: 0 ms (100%) š Lesson Learned: Sometimes sorting logic depends on combination, not value. #LeetCode #Python #CodingJourney #DSA #100DaysOfCode #Sorting #ProblemSolving
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development