✅ Day 51 of 100 Days LeetCode Challenge Problem: 🔹 #973 – K Closest Points to Origin 🔗 https://lnkd.in/gzp_xraa Learning Journey: 🔹 Today’s problem focused on finding the k points closest to the origin in a 2D plane. 🔹 I calculated the squared Euclidean distance for each point to avoid unnecessary square root operations. 🔹 Using a min-heap, I efficiently retrieved the smallest distances. 🔹 A hashmap helped group points with the same distance, ensuring correct retrieval of coordinates. Concepts Used: 🔹 Heap / Priority Queue 🔹 Euclidean Distance 🔹 Hash Map 🔹 Greedy Selection Key Insight: 🔹 Squared distance is sufficient for comparison and avoids extra computation. 🔹 Heaps are ideal for efficiently extracting the smallest (or largest) k elements. 🔹 Choosing the right data structure significantly simplifies implementation. #LeetCode #DataStructures #Algorithms #CodingInterview #SoftwareEngineering #SoftwareDeveloper #ProblemSolving #Programming #ComputerScience #TechCareers #100DaysOfCode #DailyCoding #Consistency #LearningInPublic #Python #BackendDevelopment #InterviewPreparation #TechCommunity
LeetCode Challenge Day 51: K Closest Points to Origin
More Relevant Posts
-
✅ Day 59 of 100 Days LeetCode Challenge Problem: 🔹 #3857 – Minimum Cost to Split into Ones 🔗 https://lnkd.in/g-7ARYJV Learning Journey: 🔹 Today’s problem focused on minimizing the total cost of splitting an integer n into n ones. 🔹 Each split divides a number x into a and b such that a + b = x, with cost a × b. 🔹 The key observation is that splitting as evenly as possible at every step minimizes the total accumulated cost. 🔹 This creates a divide-and-conquer pattern where balanced partitions reduce overall multiplication cost. Concepts Used: 🔹 Greedy Strategy 🔹 Divide and Conquer 🔹 Mathematical Cost Analysis 🔹 Stack / Simulation Approach Key Insight: 🔹 Balanced splits minimize product cost at each stage. 🔹 The total minimum cost follows a structured pattern based on recursive halving. 🔹 Recognizing optimal partitioning significantly simplifies the solution logic. #LeetCode #WeeklyContest #DataStructures #Algorithms #CodingInterview #SoftwareEngineering #ProblemSolving #100DaysOfCode #CompetitiveProgramming #Python #TechCommunity
To view or add a comment, sign in
-
-
✅ Day 58 of 100 Days LeetCode Challenge Problem: 🔹 #1680 – Concatenation of Consecutive Binary Numbers 🔗 https://lnkd.in/gt22hnfF Learning Journey: 🔹 Today’s problem involved concatenating the binary representations of numbers from 1 to n. 🔹 I generated binary strings using bin(i)[2:] and appended them sequentially. 🔹 After forming the final binary string, I converted it back to an integer. 🔹 Since the result can be very large, I applied modulo 10**9+7. Concepts Used: 🔹 Binary Representation 🔹 String Manipulation 🔹 Modular Arithmetic 🔹 Simulation Key Insight: 🔹 Direct string concatenation works but is not optimal for large n. 🔹 Efficient solutions avoid large intermediate strings by using bit shifts and modular arithmetic at each step. 🔹 Understanding bit-length growth is crucial for optimization in binary construction problems. #LeetCode #DataStructures #Algorithms #CodingInterview #SoftwareEngineering #SoftwareDeveloper #ProblemSolving #Programming #ComputerScience #TechCareers #100DaysOfCode #DailyCoding #Consistency #LearningInPublic #Python #BackendDevelopment #InterviewPreparation #TechCommunity
To view or add a comment, sign in
-
-
✅ Day 63 of 100 Days LeetCode Challenge Problem: 🔹 #1758 – Minimum Changes To Make Alternating Binary String 🔗 https://lnkd.in/gSY9BDhw Learning Journey: 🔹 Today’s problem focused on converting a binary string into an alternating pattern with minimum changes. 🔹 There are only two valid alternating patterns: starting with '0' (0101...) or starting with '1' (1010...). 🔹 I counted mismatches for both patterns while iterating through the string. 🔹 The answer is the minimum number of flips required between the two possibilities. Concepts Used: 🔹 String Traversal 🔹 Pattern Matching 🔹 Greedy Counting 🔹 Parity Indexing Key Insight: 🔹 When only two structural patterns are possible, evaluate both and choose the minimum cost. 🔹 Index parity (i % 2) is a clean way to enforce alternating constraints. 🔹 Comparing against expected patterns avoids unnecessary string reconstruction. #LeetCode #DataStructures #Algorithms #CodingInterview #SoftwareEngineering #SoftwareDeveloper #ProblemSolving #Programming #ComputerScience #TechCareers #100DaysOfCode #DailyCoding #Consistency #LearningInPublic #Python #BackendDevelopment #InterviewPreparation #TechCommunity
To view or add a comment, sign in
-
-
✅ Day 72 of 100 Days LeetCode Challenge Problem: 🔹 #3868 – Minimum Cost to Equalize Arrays Using Swaps 🔗 https://lnkd.in/gwbcmecy Learning Journey: 🔹 Today’s problem involved making two arrays identical with the minimum number of cross-array swaps. 🔹 Swapping within the same array is free, but swapping elements between arrays costs 1 operation. 🔹 I used Counter to count the frequency of elements in both arrays. 🔹 Then I combined the counters to check the total occurrences of each element. 🔹 If any element has an odd total frequency, it’s impossible to distribute it equally between both arrays. 🔹 Otherwise, I calculated the difference in counts between the two arrays to determine how many elements must be swapped. Concepts Used: 🔹 Frequency Counting (Counter) 🔹 Hash Maps 🔹 Greedy Counting Logic 🔹 Swap Balancing Key Insight: 🔹 For the arrays to become identical, every element must appear an even number of times across both arrays. 🔹 The imbalance of each element indicates how many swaps are required, and dividing appropriately accounts for pairwise swaps. 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 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 75 of 100 Days LeetCode Challenge Problem: 🔹 #415 – Add Strings 🔗 https://lnkd.in/gHVN5VfP Learning Journey: 🔹 Today’s problem required adding two numbers represented as strings without directly using built-in conversion functions. 🔹 I implemented a helper function to convert a string into its numeric value by iterating through digits and multiplying them with the correct powers of 10. 🔹 After converting both strings to integers, I performed the addition. 🔹 Then, I converted the result back into a string by extracting digits using modulo (%) and reversing the constructed list. Concepts Used: 🔹 String to Number Conversion 🔹 Mathematical Digit Handling 🔹 Modulo & Division 🔹 String Construction Key Insight: 🔹 Manually converting between string and integer helps understand how numbers are built and processed internally. 🔹 Constructing the result in reverse and then reversing it ensures correct digit order. Complexity: 🔹 Time: O(n + m) 🔹 Space: O(n + m) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #SoftwareEngineering #Python #ProblemSolving #LearningInPublic #TechCareers
To view or add a comment, sign in
-
-
✅ Day 76 of 100 Days LeetCode Challenge Problem: 🔹 #75 – Sort Colors 🔗 https://lnkd.in/gpH9fEJu Learning Journey: 🔹 Today’s problem required sorting an array containing only 0s, 1s, and 2s (representing colors) in-place without using built-in sort. 🔹 I implemented a selection sort approach, where for each index, I searched for the minimum element in the remaining array. 🔹 Once found, I swapped it with the current position to gradually build the sorted array. 🔹 This ensured the array was sorted in ascending order (0 → 1 → 2). Concepts Used: 🔹 Selection Sort 🔹 In-place Swapping 🔹 Nested Iteration Key Insight: 🔹 Even though the problem has an optimal linear-time solution (Dutch National Flag algorithm), a simple sorting approach like selection sort still works correctly. 🔹 Iteratively placing the smallest remaining element ensures correctness, though not optimal efficiency. 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 65 of 100 Days LeetCode Challenge Problem: 🔹 #394 – Decode String 🔗 https://lnkd.in/gD2KzChY Learning Journey: 🔹 Today’s problem involved decoding encoded strings with the pattern k[encoded_string]. 🔹 The key challenge was handling nested encodings, where brackets can appear inside other brackets. 🔹 I used a stack to store the current string and repeat count whenever a [ appears. 🔹 When encountering ], I popped the previous state and expanded the current substring accordingly. Concepts Used: 🔹 Stack Data Structure 🔹 String Manipulation 🔹 Parsing Nested Structures 🔹 Simulation Key Insight: 🔹 Each [ marks the start of a new decoding context, which can be stored in a stack. 🔹 When ] appears, the substring is repeated k times and merged with the previous context. 🔹 This approach handles nested patterns cleanly with a single linear pass. 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
-
-
Just solved “Longer Contiguous Segments of Ones than Zeros” on LeetCode with 0 ms runtime ⚡ Instead of storing segments or using extra space, I approached it with a single pass linear scan. 💡 My approach: Maintain two counters: count_1 → current streak of 1s count_0 → current streak of 0s Maintain two variables: maximum_1 → longest contiguous 1s maximum_0 → longest contiguous 0s While iterating through the string: If the character is '1', increase count_1 and reset count_0 If the character is '0', increase count_0 and reset count_1 Continuously update the maximum streaks Finally check if max(1s) > max(0s) ✨ Why this works well Only one traversal O(n) time complexity O(1) space complexity Clean and simple logic Always fascinating how simple state tracking can solve problems efficiently. Back to solving more problems and sharpening problem-solving skills! 🔥 #leetcode #coding #datastructures #algorithms #programming #python #codingpractice #problemSolving #softwareengineering #techlearning #computerscience #developers #100daysofcode #codingjourney #womenintech 🚀
To view or add a comment, sign in
-
-
✅ Day 77 of 100 Days LeetCode Challenge Problem: 🔹 #77 – Combinations 🔗 https://lnkd.in/gNFFZQYw Learning Journey: 🔹 Today’s problem required generating all possible combinations of k numbers from the range [1, n]. 🔹 I used a backtracking approach to build combinations step by step. 🔹 At each step, I added a number to the current path and recursively explored further choices. 🔹 Once the size of the current combination reached k, I added it to the result. 🔹 I also applied a pruning condition to stop unnecessary recursion when there aren’t enough elements left to complete a combination. Concepts Used: 🔹 Backtracking 🔹 Recursion 🔹 Combinatorics 🔹 Pruning Optimization Key Insight: 🔹 Backtracking systematically explores all possible combinations while maintaining constraints. 🔹 Pruning helps reduce unnecessary recursive calls, improving efficiency significantly. Complexity: 🔹 Time: O(C(n, k)) 🔹 Space: O(k) (excluding output) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #SoftwareEngineering #Python #ProblemSolving #LearningInPublic #TechCareers
To view or add a comment, sign in
-
Explore related topics
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