🚀 Day 2 of My LeetCode Journey Today I solved 2 interesting problems that strengthened my understanding of data structures and logic building 👇 🔹 1. Insert Delete GetRandom (O(1)) This problem was all about designing an efficient data structure. I learned how to combine: ✔️ HashMap (for O(1) lookup) ✔️ Array/List (for O(1) random access) 💡 Key takeaway: To achieve constant time complexity, sometimes you need to blend multiple data structures smartly. 🔹 2. Check If All 1's Are at Least Length K Places Away This problem focused on iteration and condition checking. 💡 Key takeaway: Track the position of the last seen 1 and ensure the distance condition is maintained. 🔥 What I’m improving daily: • Problem-solving mindset • Writing optimized code • Thinking in edge cases Consistency > Perfection 💯 #Day2 #LeetCode #Python #CodingJourney #ProblemSolving #100DaysOfCode
LeetCode Day 2: Data Structures and Problem-Solving
More Relevant Posts
-
𝐃𝐚𝐲 𝟏𝟑/𝟑𝟎 I used to think 𝐓𝘂𝗽𝗹𝗲𝘀 were just "limited Lists." After all, why would I want a collection I can’t change? But , I realized that 𝗜𝗺𝗺𝘂𝘁𝗮𝗯𝗶𝗹𝗶𝘁𝘆 is a superpower. In a professional codebase, you don't just write code for yourself; you write it so others 𝗱𝗼𝗻'𝘁 𝗮𝗰𝗰𝗶𝗱𝗲𝗻𝘁𝗮𝗹𝗹𝘆 𝗯𝗿𝗲𝗮𝗸 it. 📍 Lists [] say: "This data is a work in progress. It will grow, shrink, or change." 📍 Tuples () say: "This data is a constant. It is a single unit that must stay exactly as it is." 👉🏻Why this matters for "Job-Ready" code: 1️⃣ 𝗗𝗮𝘁𝗮 𝗜𝗻𝘁𝗲𝗴𝗿𝗶𝘁𝘆 : If you’re storing something like GPS coordinates (lat, long), you don't want a bug to accidentally change the latitude halfway through. A Tuple makes that mistake impossible. 2️⃣ 𝗣𝗲𝗿𝗳𝗼𝗿𝗺𝗮𝗻𝗰𝗲 : Because they are fixed in size, 𝗣𝘆𝘁𝗵𝗼𝗻 handles Tuples faster than Lists. It’s a cleaner way to 𝙢𝙖𝙣𝙖𝙜𝙚 𝙢𝙚𝙢𝙤𝙧𝙮. 𝗞𝗲𝘆 𝗧𝗮𝗸𝗲𝗮𝘄𝗮𝘆: Just because you can use a List for everything doesn't mean you should Professional coding is about choosing the tool that best protects your data. #Python #30DaysOfCode #SoftwareEngineering #CleanCode #LearningInPublic #Day13
To view or add a comment, sign in
-
-
update from previous post[https://lnkd.in/dVx_NrDQ] From "Arrow Code" to Clean Architecture. 🏹 ➡️ 🧱 I’ve hit a major turning point in my Python journey. I realized my code was starting to look like an arrow—layers upon layers of if statements and while loops pushing my logic further and further to the right. In professional dev circles, they call this Arrow Code, and it's a nightmare to maintain. Here’s how I "flattened" my latest project: ✅ Decomposition: I broke down massive, nested blocks into small, dedicated functions. Each function now does one thing well, making the main logic readable at a single glance. ✅ The "Gatekeeper" Pattern: Instead of scattered validation, I built a centralized handler to act as a security guard for all user inputs. ✅ State Management: I’m now mastering the "Baton Pass"—using return values and arguments to move data (like budgets) safely through the app instead of relying on global variables. ✅ Professional Workflow: I’m officially using Git branches and Pull Requests on GitHub to review my own work and track my architectural improvements. The goal isn't just to write code that the computer understands; it’s to write code that other humans can read. 🚀 #CleanCode #Python #SoftwareEngineering #Refactoring #CodingJourney #BuildInPublic
To view or add a comment, sign in
-
-
🚀 Day 344 of solving 365 medium questions on LeetCode! 🔥 Today’s challenge: “89. Gray Code” ✅ Problem: You are given an integer n. Your goal is to generate an n-bit Gray code sequence, which is an array of 2^n integers where every adjacent pair of numbers (including the first and last numbers) differs by exactly one single bit in their binary representation. ✅ Approach (Bit Manipulation / The Formula) You could solve this using backtracking or mirroring, but there is a mathematical cheat code that solves it instantly! Find the Size: First, we need to know exactly how many numbers to generate. For an n-bit sequence, there are exactly 2^n numbers. I used a bitwise left shift (1 << n) to calculate this size instantly. The Magic Formula: The i-th number in a standard Gray code sequence can always be found using the exact formula: i ^ (i >> 1). This takes the number, shifts its bits to the right by one, and applies a bitwise XOR against the original number. List Comprehension: I packed this entire logic into a single Python list comprehension that loops from 0 up to our calculated size. It applies the magic formula to every index i, generating the perfect sequence in one go! ✅ Key Insight Bitwise operations are essentially black magic when you know the right formulas. Recognizing that Gray code has a direct integer-to-sequence mapping completely eliminates the need for messy recursive state-tracking. What looks like a complex combinatorial sequence problem is actually just a one-line math trick! ✅ Complexity Time: O(2^n) — We must iterate to generate exactly 2^n elements for the sequence. Space: O(1) — Excluding the space required for the output array, the mathematical generation uses strictly constant auxiliary memory. 🔍 Python solution attached! 🔥 Flexing my coding skills until recruiters notice! #LeetCode365 #BitManipulation #Math #Python #ProblemSolving #DSA #Coding #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 From Confusion → Clarity: My Approach to “Sort the People” (LeetCode) Today I solved the Sort the People problem, and instead of jumping straight into sorting tricks, I focused on building clarity step by step 👇 🔍 My Thought Process: First, I paired each name with its corresponding height using a list (like a mini mapping). Then, I sorted this list based on height. Since the problem required descending order, I simply reversed the sorted list. Finally, I extracted only the names in the correct order. 💡 Key Learning: Sometimes, the simplest approach is the best one. Instead of overcomplicating with advanced data structures, breaking the problem into smaller transformations made it super manageable. 🧠 What this improved for me: Understanding how to use lambda for sorting Confidence in handling paired data (name + value problems) Thinking in steps rather than jumping to optimization ⚡ Code Strategy in One Line: Pair → Sort → Reverse → Extract Consistency > Speed. One problem at a time. 💪 📈 If you're also grinding DSA, keep going — progress compounds! #DSA #LeetCode #CodingJourney #Python #ProblemSolving #Consistency #TechGrowth #100DaysOfCode #WomenInTech #FutureEngineer
To view or add a comment, sign in
-
-
💻 Why Follow My GitHub Journey? Because here, code is not just code. It’s solutions, learning, and creativity. ✅ Highlights: Projects in Python, SQL, React, and AI/ML Real-world datasets for hands-on learning Clear documentation & reusable code 👀 Take a look at my repositories: https://lnkd.in/dqgHkRQm� 💬 CTA: Star ⭐ your favorite repo, fork it, or drop me a message. I love collaborating with like-minded data enthusiasts!
To view or add a comment, sign in
-
I had a funny moment while coding today. 😁 Everything was going great. Data was ready. Then I typed the usual code: X = df.drop("price", axis=1) y = df["price"] And my brain just stopped: "Wait... why do we always use X and y? Who made this a rule?" 🤨😭 I looked it up, and it is actually just simple math 📐: Capital X = A big group of data (many columns). Small y = Just one thing (one column). Big data gets a big letter. Small data gets a small letter. 🤯 Do I have to use them? No. I could use normal names like features and price. But am I going to do that? Nope! Tomorrow I will use X and y again. It is just a habit now! 🌚 It is funny how in ML, the biggest questions come from the smallest things. 😅 Be honest: Do you use normal names, or do you also just use X and y? 👇 #MachineLearning #Python #DataScience #CodingLife #SimpleCode
To view or add a comment, sign in
-
GitHub moves faster than we can "git pull." I spent the morning auditing this week's Top 12 trending repositories so you don't have to drown in your "Star" list. The Weekly Signal: Dominant Language: Python is leading the pack with 6 out of 12 top repos. AI agents, foundation models, and dev tooling are all written in Python this week. Top Pick: hermes-agent by NousResearch gained 14,811 stars this week. A modular AI agent framework that supports multi-LLM workflows out of the box. Rising Star: openscreen by siddharthvaddem pulled 13,938 stars. An open-source Screen Studio alternative. Free product demos with no watermarks. I've mapped out the technical specs, practical use cases, and star growth for all 12 repos into a clean dashboard. Which of these are you cloning today? Let's talk architecture in the comments. #OpenSource #GitHub #AI #Python #DeveloperTools #TechTrends
To view or add a comment, sign in
-
I was wondering how Claude/Codex and other agentic tools optimize around context windows and perform local tasks. I've done some research (Claude helped, but also gaslighted me on a Friday night no less) and put together a tutorial python notebook that covers different strategies like tools/agentic loops (see the github for the source code). Most agent tutorials hand you a framework and hide the hard parts. This one builds every piece by hand — context budgets, file retrieval, planning, reflection — so you understand what the frameworks are actually doing. By the end you have a working coding agent that can read a codebase, plan multi-step tasks, write and diff files, run tests, and revise its own plan when something goes wrong. It runs on Google colab and doesn't need any installation. If you have some Python literacy, you'll get a lot out of it (hopefully). If you don't, just running the examples, staring at the parameters and looking at the graphical-ish output should give you a fair bit of intuition on what's happening under the covers. Bonus: And if you ❤️Ollama, yes it runs on Ollama too. Completely offline. All your data stays local. Love it? Hate it? Found bugs? Didn't understand something? All reasons to drop me a DM or comment down below. Just dont ask me my star sign (it's Aries). 👉 Open in Colab: https://lnkd.in/eKuUvZBG ⭐ GitHub: https://lnkd.in/eM-wFthp Here's a little overview video for the tutorial created by NotebookLM using the source code as the primary source of truth. #AI #MachineLearning #LLM #Python #AgentAI #OpenSource #Ollama #SoftwareEngineering #BuildInPublic
To view or add a comment, sign in
-
Best for: Posting late at night or early morning to show your dedication. Headline: While the world sleeps, the code keeps building. 🌙 It’s been a high-energy day with 83+ profile visits. People are asking: "What are you building in that 2024 repo?" The answer is simple: The future of my workflow. I am documenting my journey of turning raw Python scripts into scalable, automated solutions. From smart profiling to interactive Plotly dashboards, I’m building a library that works for me, so I don't have to work twice. If you haven’t seen it yet, come take a look and see why the tech community is stopping by my profile. ⭐ Support the work on GitHub: 🔗 https://lnkd.in/dGvJaB7a #DataScience #Hustle #Coding #Python #Automation #Shafiq73 #GitHub
To view or add a comment, sign in
-
Headline: 🚀 From Confused to Confident: Solving LeetCode 2906! Body: Ever stared at a problem statement and thought, "Where do I even start?" That was me today with LeetCode 2906: Construct Product Matrix. The task seemed simple: For every cell in a matrix, calculate the product of all other elements. But the catch? Doing it efficiently without hitting a Time Limit Exceeded (TLE) error. 💡 The Breakthrough: I realized this is essentially a 2D version of the classic "Product of Array Except Self." Instead of brute-forcing it (which would be O(N²)), I used the Prefix & Suffix Product approach. 🎓 How I visualized it (The Story): Imagine a classroom photo where every student needs to calculate the "score" of everyone else except themselves. 1️⃣ Forward Pass: Calculate the product of everyone standing to your left. 2️⃣ Backward Pass: Calculate the product of everyone standing to your right. 3️⃣ Multiply: Left × Right = Your Answer! By treating the 2D matrix as a continuous stream, I optimized the solution to: ✅ Time Complexity: O(m × n) ✅ Space Complexity: O(1) (excluding output matrix) 🔑 Key Takeaway: Don't rush to code. Spend time visualizing the data flow. Sometimes, breaking a 2D problem into a 1D logic stream makes all the difference. Has anyone else tackled this problem? What was your approach? Let's discuss in the comments! 👇 #LeetCode #DSA #Coding #ProblemSolving #SoftwareEngineering #LearningJourney #Python #Algorithms #TechCommunity
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