Day 32 / #120DaysOfCode – LeetCode Challenge Today’s focus: Arrays & Majority Voting Algorithm ✅ Problem Solved: • Majority Element II 💻 Language: Python 📚 Key Learnings: • Applied Boyer-Moore Voting Algorithm (extended version) • Learned how to track two candidates for n/3 majority • Understood the importance of validation step after candidate selection • Improved ability to handle edge cases in frequency problems Consistency builds confidence 🚀 Every day = 1% better 💪 🔗 LeetCode Profile: https://lnkd.in/gbeMKcv5 #LeetCode #Python #DSA #Arrays #Algorithms #Consistency #CodingJourney #120DaysOfCode
Arrays & Majority Voting Algorithm in Python
More Relevant Posts
-
Day 43/100 – #100DaysOfCode 🚀 Solved LeetCode #2610 – Convert an Array Into a 2D Array With Conditions (Python). Today I practiced hashmap (frequency counting) to construct a 2D array based on given conditions. Approach: 1) Create a frequency map to count occurrences of each element. 2) Initialize an empty result list. 3) While the frequency map is not empty: 4) Create a new row. 5) Iterate through keys and add each number once to the row. 6) Decrease its frequency and remove it if it becomes zero. 7) Add the row to the result. 8) Return the final 2D array. Time Complexity: O(n) Space Complexity: O(n) Learning how frequency maps help in structuring data efficiently 💪 #LeetCode #Python #DSA #HashMap #Arrays #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Back to consistency 💻🚀 Recently, I worked on implementing Pascal’s Triangle in Python — and it turned out to be a great exercise in logic building. While solving this, I learned: 🔹 How each row depends on the previous one 🔹 Better understanding of nested loops 🔹 Using mathematical logic instead of brute force It’s interesting how such a simple-looking pattern involves deeper thinking behind the scenes. Here’s my implementation 👇 Small steps like these are helping me build a strong foundation in Data Structures & Algorithms. #Python #DSA #CodingJourney #LearningInPublic #100DaysOfCode
To view or add a comment, sign in
-
-
Group Anagrams: Frequency Array as Hashable Key Sorting each string costs O(k log k) per string. Character frequency array is O(k) and creates identical signature for anagrams. Fixed 26-element array converted to tuple serves as hashable HashMap key — faster, cleaner grouping. Frequency Signature: Character counts uniquely identify anagram groups without sorting. Tuple conversion makes array hashable for dict keys. Pattern applies to document clustering, duplicate detection. Time: O(n × k) vs O(n × k log k) sorting | Space: O(n × k) #FrequencyArray #Anagrams #HashMap #KeyOptimization #Python #AlgorithmOptimization #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 24/100 – DSA Journey Problem: Intersection of Two Arrays Initially thought of using loops, but that would increase time complexity. Then realized the problem requires only unique common elements, which makes sets a perfect fit. Converted both arrays into sets and used intersection to directly get the result in an efficient way. Key Learning: Choosing the right data structure can simplify the entire problem. #Day24 #100DaysOfCode #DSA #Python #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
Today, I learned how to take user input in Python using the input() function. This allows programs to interact with users and collect data such as name, age, and city. I also learned how to convert input into numbers using int() and float(), which is very important for calculations and data processing. #Day2 #Python #LearningJourney #DataScience #MachineLearning #Consistency
To view or add a comment, sign in
-
Last Stone Weight: Max-Heap via Negation for Collision Simulation Python's heapq is min-heap only. Simulate max-heap by negating values. Repeatedly extract two largest stones (most negative), compute difference, reinsert. Continue until one/zero stones remain. Max-Heap Workaround: Negating values transforms min-heap to max-heap. This pattern applies whenever max-heap needed in Python. Remember to negate back when extracting final values. Time: O(n log n) | Space: O(n) #Heap #MaxHeap #NegationTrick #PriorityQueue #Python #AlgorithmDesign #SoftwareEngineering
To view or add a comment, sign in
-
-
Search Insert Position: Left Pointer as Natural Insertion Index When binary search terminates without finding target, left pointer automatically points to correct insertion position. No special handling needed — the loop invariant guarantees left is where target belongs to maintain sorted order. Termination Property: When l >= r, left has crossed to insertion position. This binary search property eliminates need for post-loop calculation. Time: O(log n) | Space: O(1) #BinarySearch #InsertPosition #LoopInvariant #SortedArrays #Python #AlgorithmDesign #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 39 / #120DaysOfCode – LeetCode Challenge ✅ Problem Solved: • Integer to Roman 💻 Language: Python 📚 Key Learnings: • Learned how to map numerical values to symbolic representations • Used greedy approach for optimal conversion • Understood importance of ordered value-symbol pairing • Practiced handling special subtraction cases (IV, IX, XL, etc.) • Improved skills in writing structured and readable logic Consistency + Logic = Growth 🚀 🔗 LeetCode Profile: https://lnkd.in/gbeMKcv5 #LeetCode #Python #DSA #Algorithms #CodingJourney #Greedy #120DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 3 — Python Journey Today’s focus was on float operations in Python (working with decimal numbers). 📌 What I learned: Float declaration Addition, subtraction, multiplication, division Rounding values using round() Scientific notation Precision handling in floats 💡 What I found interesting: Float values are not always 100% accurate due to precision limitations. Even simple calculations can sometimes give unexpected results. Understanding this early is important, especially for real-world applications like finance or data science. Step by step, trying to build a strong foundation. #Day3 #Python #CodingJourney #LearnInPublic #Consistency
To view or add a comment, sign in
-
-
🔁 Exploring Sorting Algorithms in Python Today I practiced two fundamental sorting techniques: ✅ Bubble Sort ✅ Selection Sort 💡 Key Learnings: * Bubble Sort repeatedly swaps adjacent elements to push larger elements to the end * Selection Sort selects the minimum element and places it in the correct position * Understanding time complexity becomes clearer when you count operations manually #Python #DataStructures #Algorithms #CodingJourney #100DaysOfCode #LearningInPublic
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