✅ Day 64 of 100 Days LeetCode Challenge Problem: 🔹 #1784 – Check if Binary String Has at Most One Segment of Ones 🔗 https://lnkd.in/gpJYed9J Learning Journey: 🔹 Today’s problem focused on determining whether a binary string contains only one contiguous segment of '1's. 🔹 Since the string has no leading zeros, the first character is always '1'. 🔹 If a '1' appears again after a '0', it indicates the start of a second segment. 🔹 A single pass through the string is enough to detect this pattern. Concepts Used: 🔹 String Traversal 🔹 Pattern Detection 🔹 Conditional Logic Key Insight: 🔹 The pattern "01" followed by another '1' reveals multiple segments of ones. 🔹 Detecting this transition allows us to solve the problem efficiently. Complexity: 🔹 Time: O(n) 🔹 Space: O(1) 💬 What’s your favorite trick for solving binary string problems? #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #SoftwareEngineering #Python #ProblemSolving #LearningInPublic #TechCareers
LeetCode Challenge: Check Binary String for One Segment of Ones
More Relevant Posts
-
✅ Day 78 of 100 Days LeetCode Challenge Problem: 🔹 #3110 – Score of a String 🔗 https://lnkd.in/g9jgxcdK Learning Journey: 🔹 Today’s problem involved calculating the score of a string based on the absolute differences between ASCII values of adjacent characters. 🔹 I iterated through the string starting from index 1 and computed the difference between the current and previous character using ord(). 🔹 For each pair, I added the absolute difference to a running total. 🔹 This approach efficiently accumulates the score in a single pass. Concepts Used: 🔹 String Traversal 🔹 ASCII Value Conversion (ord()) 🔹 Absolute Difference Calculation Key Insight: 🔹 The problem reduces to comparing adjacent elements, making it a straightforward linear scan. 🔹 Using ord() allows direct access to ASCII values, simplifying the computation. Complexity: 🔹 Time: O(n) 🔹 Space: O(1) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #SoftwareEngineering #Python #ProblemSolving #LearningInPublic #TechCareers
To view or add a comment, sign in
-
-
✅ Day 68 of 100 Days LeetCode Challenge Problem: 🔹 #1207 – Unique Number of Occurrences 🔗 https://lnkd.in/g2vjwwft Learning Journey: 🔹 Today’s problem required checking whether the frequency of each element in an array is unique. 🔹 I first used Counter to count how many times each number appears in the array. 🔹 Then I extracted the occurrence counts using .values(). 🔹 To verify uniqueness, I compared the length of the occurrences list with the length of a set created from those values. 🔹 If both lengths match, it means all occurrence counts are unique. Concepts Used: 🔹 Hash Map / Frequency Counting 🔹 Python Counter from collections 🔹 Sets for Uniqueness Check Key Insight: 🔹 Converting values to a set removes duplicates automatically. 🔹 If the size of the set equals the number of frequency values, then all occurrence counts are distinct. Complexity: 🔹 Time: O(n) 🔹 Space: O(n) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #SoftwareEngineering #Python #ProblemSolving #LearningInPublic #TechCareers
To view or add a comment, sign in
-
-
✅ Day 87 of 100 Days LeetCode Challenge Problem: 🔹 #2840 – Check if Strings Can be Made Equal With Operations II 🔗 https://lnkd.in/gY73RBb5 Learning Journey: 🔹 Today’s problem extended the previous one, allowing swaps between indices where the difference is even. 🔹 I observed that this again partitions the string into two independent groups: • Even indices (0, 2, 4, …) • Odd indices (1, 3, 5, …) 🔹 I extracted characters from even and odd positions separately for both strings. 🔹 Then, I sorted these groups and compared them between s1 and s2. 🔹 If both even-index groups and odd-index groups match, the strings can be made equal. Concepts Used: 🔹 String Manipulation 🔹 Index Grouping (Parity-based) 🔹 Sorting 🔹 Greedy Observation Key Insight: 🔹 Since swaps are allowed only between indices with even distance, characters can only move within their parity group. 🔹 Therefore, the problem reduces to checking if both parity groups have identical character distributions. Complexity: 🔹 Time: O(n log n) 🔹 Space: O(n) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #SoftwareEngineering #Python #ProblemSolving #LearningInPublic #TechCareers
To view or add a comment, sign in
-
-
✅ Day 69 of 100 Days LeetCode Challenge Problem: 🔹 #1009 – Complement of Base 10 Integer 🔗 https://lnkd.in/geVPugvi Learning Journey: 🔹 Today’s challenge involved finding the bitwise complement of a base-10 integer. 🔹 I first converted the integer into its binary representation using bin(n)[2:] to remove the 0b prefix. 🔹 Then I iterated through each bit and flipped it: • 0 becomes 1 • 1 becomes 0 🔹 After constructing the flipped binary string, I converted it back to a decimal integer using int(s, 2). Concepts Used: 🔹 Binary Representation 🔹 Bit Manipulation 🔹 String Traversal 🔹 Base Conversion (Binary → Decimal) Key Insight: 🔹 Converting the number to binary makes it easy to flip bits directly. 🔹 After inversion, converting the binary string back to base-10 produces the required complement. Complexity: 🔹 Time: O(b) where b is the number of bits in n 🔹 Space: O(b) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #SoftwareEngineering #Python #ProblemSolving #LearningInPublic #TechCareers
To view or add a comment, sign in
-
-
✅ Day 74 of 100 Days LeetCode Challenge Problem: 🔹 #653 – Two Sum IV: Input is a BST 🔗 https://lnkd.in/g9vDFKMA Learning Journey: 🔹 Today’s problem required checking whether there exist two nodes in a Binary Search Tree whose values sum to k. 🔹 I performed a Depth-First Search (DFS) traversal using a stack to visit all nodes of the tree. 🔹 While traversing, I stored each node’s value in a list. 🔹 Then I used a hash set to track visited values and checked whether the complement (k - value) already exists. 🔹 If the complement is found, it means two numbers sum to k, so the function returns True. Concepts Used: 🔹 Depth-First Search (DFS) 🔹 Stack-based Tree Traversal 🔹 Hash Set for Fast Lookup 🔹 Two Sum Pattern Key Insight: 🔹 The classic Two Sum approach works well after collecting values from the BST. 🔹 Using a set allows O(1) lookup, making it efficient to check complements during iteration. Complexity: 🔹 Time: O(n) 🔹 Space: O(n) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #SoftwareEngineering #Python #ProblemSolving #LearningInPublic #TechCareers
To view or add a comment, sign in
-
-
✅ Day 79 of 100 Days LeetCode Challenge Problem: 🔹 #451 – Sort Characters By Frequency 🔗 https://lnkd.in/gMAzHVvS Learning Journey: 🔹 Today’s problem required sorting characters in a string based on their frequency in decreasing order. 🔹 I first built a frequency map (hash map) to count occurrences of each character. 🔹 Then I grouped characters by their frequency and stored them accordingly. 🔹 Finally, I sorted the frequencies in descending order and constructed the result string by repeating characters based on their counts. Concepts Used: 🔹 Hash Map (Frequency Counting) 🔹 Sorting (Descending Order) 🔹 String Construction Key Insight: 🔹 Instead of sorting characters directly, grouping them by frequency makes it easier to reconstruct the result efficiently. 🔹 Sorting only the frequency keys reduces unnecessary operations. Complexity: 🔹 Time: O(n log k) (k = unique characters) 🔹 Space: O(n) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #SoftwareEngineering #Python #ProblemSolving #LearningInPublic #TechCareers
To view or add a comment, sign in
-
-
✅ Day 70 of 100 Days LeetCode Challenge Problem: 🔹 #1051 – Height Checker 🔗 https://lnkd.in/g7bmj62W Learning Journey: 🔹 Today’s problem required identifying how many students are not standing in the correct order according to their heights. 🔹 I first created a sorted version of the heights array to represent the expected order. 🔹 Then I compared each element of the original list with the corresponding element in the sorted list. 🔹 Every mismatch indicates a student standing in the wrong position, so I incremented a counter for each difference. Concepts Used: 🔹 Sorting 🔹 Array Comparison 🔹 Iteration Key Insight: 🔹 Instead of rearranging elements, simply comparing the original array with its sorted version reveals how many indices differ. 🔹 Each mismatch directly contributes to the final count. Complexity: 🔹 Time: O(n log n) 🔹 Space: O(n) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #SoftwareEngineering #Python #ProblemSolving #LearningInPublic #TechCareers
To view or add a comment, sign in
-
-
LeetCode 23: Merge k sorted list: You are given an array of k linked-lists lists, each linked-list is sorted in ascending order. Merge all the linked-lists into one sorted linked-list and return it. Approach: Simple and straightforward, iterate through each of the linked-list in the given list, push each node's value into a priority queue using heapq module, create a new linked-list using the elements of priority queue. Time complexity: O(n logn) where n is the total number of values. Space complexity: O(n) #Python #LeetCode #DSA #CompetitiveProgramming #DataStructures #Algorithms #ProblemSolving
To view or add a comment, sign in
-
-
🚀 DSA Practice Update! Solved Remove Duplicates from Sorted Array on LeetCode with an optimized approach. Brute Force: O(n log n) time | O(n) space Optimized (Two Pointer):O(n) time | O(1) space Choosing the right approach matters more than just solving the problem. The Brute Force approach removes duplicates by using extra data structures like a set and then sorting the array again. Because of sorting, its time complexity becomes O(n log n) and it also requires O(n) extra space. Additionally, it is not in-place, which makes it less efficient and not ideal for optimized solutions. “I used a two-pointer approach where one pointer tracks the position of unique elements and the other scans the array. This gives O(n) time and O(1) space complexity.” Consistency + Optimization = Growth 📈 #DSA #LeetCode #InterviewPrep #Python #CodingJourney
To view or add a comment, sign in
-
-
Today I solved Majority Element, a fundamental problem that highlights efficient array processing and algorithmic thinking. 🔹 Problem: Given an array nums of size n, return the majority element. The majority element is the element that appears more than ⌊n/2⌋ times in the array. 🔹 Approach (Boyer–Moore Voting Algorithm): Instead of counting frequencies with extra space, we can use an elegant algorithm that works in O(n) time and O(1) space. Steps: Maintain a candidate and a count. If the count becomes 0, select the current number as the new candidate. Increase count if the element matches the candidate, otherwise decrease it. 🔹 Example: Input: [2,2,1,1,1,2,2] Output: 2 🔹 Complexity: ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) 💡 This problem is a great example of how clever algorithms can eliminate the need for extra memory while maintaining efficiency. #LeetCode #Algorithms #DataStructures #Python #CodingPractice #ProblemSolving #BoyerMoore #SoftwareEngineering
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