Today I learned something interesting, I learnt to solve the classic “Single Number” problem: given an array where every element appears twice except one, find the one that appears only once. I initialise result = 0 and XOR it with each number in the array — because a ^ a = 0 and a ^ 0 = a, all duplicates cancel out, leaving the unique number. For example, with [4,2,1,2,4], the process goes: 0 ^ 4 = 4 4 ^ 2 = 6 6 ^ 1 = 7 7 ^ 2 = 5 5 ^ 4 = 1 — and the answer is 1. What I learned: 1) Bitwise operations (XOR) can give very efficient solutions. 2) Always look at the constraints: “linear time” + “constant space” guided this decision. Even when an approach works, micro-optimisation (loop style, engine behaviour) still affects performance. I’m excited to keep pushing my problem-solving skills and discovering more of these clever tricks. If you’ve got a favourite algorithm or bitwise trick, I’d love to hear it! 💬 #coding #algorithms #javascript #programming #leetcode #learning
Solved the "Single Number" problem using XOR. Learned about bitwise operations and micro-optimisation.
More Relevant Posts
-
Debugging is still crucial. Once upon a time, you'd type print() and tinker. Today, we often ask an LLM to generate code. However, I end up debugging and discarding much of that code in favor of simpler solutions "suggested" by the debugger. The debugger doesn't write the response. It indicates where the bug is. This is better than replacing parts of code with renaming, reordering, and fallbacks that suppress the error and prevent its detection. The problem isn't with LLMs. It's the approach: in this case, the debugger continues to guide you toward better solutions. LLMs are powerful tools but sometimes devious. They don't have a complete view of the projects and contexts in which they are integrated. By its very nature, debugging will remain important for a long time. Practical example: A table uses an ID of 0_0, and an array in a later step identifies it as 0. Result: an inevitable KeyError, never raised due to a fallback inserted by the LLM. There is no gap in the data. There is an inconsistency between two process steps that the model couldn't see. The debugger showed it immediately: 0 ≠ 0_0 or 0 ≠ '0'. It may seem trivial, but that's exactly what using the debugger does. #debugger #debugging #LLM #datascience #coding #Python
To view or add a comment, sign in
-
💻 Day 34 of #100DaysOfLeetCode Today’s Challenge: 83. Remove Duplicates from Sorted List 🔹 Problem: Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well. Key Insight: Because the list is already sorted, duplicates will always be adjacent—this allows us to remove them in a single pass using pointer manipulation. 🔍 Approach: Traverse the list using a pointer. Compare current node with the next node. If values are equal → skip the next node by linking to the next of next. Otherwise → move forward. 🕒 Time Complexity: O(n) 📦 Space Complexity: O(1) ✨ Key Takeaway: This problem reinforces the importance of pointer manipulation and understanding how memory references work in linked lists. A simple check can eliminate duplicates efficiently without using extra space. Link:[https://lnkd.in/gsjVxHXM] #100DaysOfLeetCode #Day34 #LeetCode #ProblemSolving #DSA #Algorithms #LinkedList #CodingChallenge #CodeNewbie #InterviewPreparation #SoftwareEngineering #Programming #CodingCommunity #TechCareers #CareerGrowth #ArjunInfoSolution
To view or add a comment, sign in
-
-
💻 Day 33 of #100DaysOfLeetCode 🔗 Today’s Challenge: Intersection of Two Linked Lists 🔹 Problem: Find the node at which two singly linked lists intersect. If the two linked lists do not intersect, return null. This is a classic problem to test understanding of linked list structure, pointer manipulation, and memory reference. 🔍 Naive Approach: Use nested loops to compare each node in list A with each node in list B. Time Complexity: O(m × n) Not efficient and not recommended for large lists. 🚀 Optimized Two-Pointer Approach: Use two pointers that traverse both lists. When one pointer reaches the end, redirect it to the head of the other list. If they intersect, the pointers will meet at the intersection node. If not, both will reach null simultaneously. 🕒 Time Complexity: O(m + n) 📦 Space Complexity: O(1) Link:[https://lnkd.in/gyTB4GqG] #100DaysOfLeetCode #Day33 #LeetCode #ProblemSolving #Algorithms #DSA #LinkedList #CodingChallenge #CodeNewbie #InterviewPreparation #SoftwareEngineering #Programming #CodingCommunity #TechCareers #CareerGrowth #ArjunInfoSolution
To view or add a comment, sign in
-
-
🚀 Day 17 of #100DaysofCode Challenge! 🚀 🔍 What is Dynamic Programming (DP), and why does it matter? I recently watched Aditya Verma’s introductory video on DP and here are the highlights: • DP is an optimization over naïve recursion — it’s about identifying when you’re solving the same sub-problem repeatedly, and instead reuse those results (overlapping sub-problems + optimal substructure). • The typical workflow: start with a recursive solution, notice repeated work → switch to memoization (top-down) → then possibly convert to tabulation (bottom-up). • The key mindset shift: Think in terms of subproblem states and transitions/choices — that’s what lets you build from smaller results to the full solution. • Use DP when brute force recursion is too slow and when the problem naturally splits into smaller pieces whose optimal solutions combine. • Base cases, initialization, and correct ordering (especially in bottom-up) are crucial — you can’t just “DP-ify” any recursion without thinking about these. #Day17 #DynamicProgramming #Algorithms #ProblemSolving #CodingMindset #SoftwareEngineering #AdityaVerma #CodingJourney
To view or add a comment, sign in
-
-
✨ Generating Valid Parentheses Using DFS Problem Link:https://lnkd.in/e97DASha Today I worked on a classic backtracking problem generating all valid parentheses combinations for a given n. The interesting part is that every step has rules: 1.You can add '(' only if you still have remaining open brackets to use 2.You can add ')' only if it does not break the balance 3.The final string must be exactly 2 * n characters and perfectly balanced ✅ This problem beautifully shows how constraints guide creativity. The solution uses DFS (Depth First Search) to explore all possible sequences, but only keeps those that remain valid at every step like making the right choices early leads to the right result later. This is one of those problems that strengthens both logic and patience in coding. Small steps → careful decisions → perfect outcome. 🚀 #DSA #Backtracking #Recursion #CPP #CodingJourney #LeetCode #SoftwareEngineering #Algorithm #ProblemSolving #DeveloperMindset #KeepCoding #LearningEveryday
To view or add a comment, sign in
-
-
Staring at endless strings of 1s and 0s? 😵💫 Learn how to effortlessly convert binary to hex, a fundamental skill for developers, engineers, and anyone working with machine code! Hexadecimal offers a more human-friendly representation of binary data, simplifying web development, network analysis, and debugging. This guide breaks down the process into easy steps: grouping, using a conversion chart, and combining! Plus, explore practical examples and even reverse the process from hex to binary. Level up your skills and bridge the gap between human logic and machine code! Ready to simplify your workflow? Check out the full guide and online binary to hex converter tool! 👇 https://lnkd.in/dnGQbcYP #binary #hexadecimal #converter #coding #programming #developmenttools
To view or add a comment, sign in
-
🚀 Day 37 of #100DaysOfCode Challenge 🚀 🧠 Problem: 🧩 LeetCode 282 — Expression Add Operators (Hard) This problem was all about exploring backtracking with arithmetic logic. We’re given a string of digits and need to insert +, -, or * between them to reach a target value. ⚙️ Approach Used backtracking to: -Pick every possible substring as the next number. -Try adding each operator before it (+, -, *). -Track three things: -current value → total so far -previous operand → to handle multiplication correctly -expression → the string we’re building -Also skipped invalid paths like numbers with leading zeros. 📘 Learning -Understood how to evaluate expressions on the fly without using eval(). -Learned to manage operator precedence (* before +/-) using recursion and previous operand adjustment. -Realized that some problems can’t be optimized further — they test how well you can prune and organize recursion. #100DaysOfCode #DSA #CodingChallenge #StriversSheet #ProblemSolving #TakeUForward #Recursion #CodingInterview #ProgrammingTips #LeetCode #Backtracking
To view or add a comment, sign in
-
-
𝐏𝐫𝐞𝐟𝐢𝐱 𝐒𝐮𝐦 — 𝐓𝐡𝐞 𝐏𝐚𝐭𝐭𝐞𝐫𝐧 𝐓𝐡𝐚𝐭 𝐓𝐮𝐫𝐧𝐬 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲 𝐈𝐧𝐭𝐨 𝐂𝐥𝐚𝐫𝐢𝐭𝐲 when you’re solving DSA, some problems feel heavy because we repeatedly calculate the same thing again and again. Prefix Sum fixes that. It simply says: 👉 “Calculate once. Reuse forever.” You create an extra array that stores cumulative values, and suddenly: Range queries become O(1) Subarray problems become predictable Target-sum problems feel easier Frequency-based logic becomes clean Prefix Sum is not just a trick — it’s a mindset shift. You stop doing brute force. You start thinking smarter. Problems where Prefix Sum helps: Range Sum Queries Subarrays equal to K Subarray count / longest subarray types Even–odd frequency problems Difference arrays Kadane variations Many DP optimizations Keep learning these patterns — they are the real shortcuts in DSA. One pattern a day. One improvement a day. Keep going. for more let's Connect : Anil Rathod #dsa #leetcode #codingjourney #problemsolving #prefixsum #codingcommunity #programming #dailycoding
To view or add a comment, sign in
-
-
I’ve been using Cursor and Claude Code since the early days — and honestly, after a phase of disappointment with Cursor, I had completely shifted to Claude Code. But Cursor 2.0 hits differently. This update isn’t just a patch — it’s a complete transformation of how AI-assisted coding feels. Here’s what stood out to me: → Multi-Agents: Run up to 8 agents in parallel on isolated workspaces — no conflicts, no chaos. → Composer Model: Their new agent model is 4× faster — perfect for fast-paced dev loops. → Browser (GA): Agents can now interact directly with web pages — a game-changer for UI-driven automation. → Sandboxed Terminals: Secure command execution with zero network access — safer testing, fewer risks. → Team Commands: Create and share prompts, rules, and workflows across your team — a real productivity boost. → Improved LSPs: Much smoother experience in large Python and TypeScript projects. → Plan Mode: Build and compare multiple agent plans in the background — parallel thinking at its best. → Enterprise Suite: Audit logs, admin control, and compliance-ready security — finally enterprise-grade. Final thought: Cursor 2.0 feels mature — fast, stable, and deeply team-oriented. If you left Cursor before, this version might just win you back. #Cursor #Claude #AItools #Developers #AgenticAI #Coding #DevTools #Productivity
To view or add a comment, sign in
-
-
"Oh, Kth Largest Element... Easy!" My first, naive attempt: Make a list. Add the new number. Sort the entire list. Return the k-th element. ...aaaand [Time Limit Exceeded] 💀 This is the "N-aive" solution. It works perfectly until you have a stream of 10,000 numbers and your add() function takes 5 seconds. The problem isn't the concept. It's the stream. You're adding one new number, but you're re-sorting everything, every single time. It's like re-organizing your entire bookshelf every time you buy one new book. The real "Aha!" moment comes when you ask the right question: "Do I really care about the 1,000th or 1,000,000th largest number?" No. You only care about the Top K. So, how do you find the Kth Largest element? You use... a Min-Heap. (Wait, what? 🤯) Yes! This is the counter-intuitive trick that makes you look like a genius. You build a min-heap (a "priority queue") that only holds k items. The smallest item in this heap (the root) is always your Kth largest element. A new number arrives. Is it smaller than the root? Ignore it. It's not in the Top K. Is it bigger? Kick out the root (the smallest of the Top K) and push the new number. Return the new root. Boom. O(log k) for every add, not O(N log N). This isn't just a LeetCode problem. This is the core logic for any real-time "Top K" system: Live video game leaderboards 🎮 Monitoring the "Top 10" slowest server response times 📈 Finding the most popular items in a streaming feed What's your favorite "counter-intuitive" algorithm? Let me know! #leetcode #datastructures #algorithms #computerscience #programming #coding #softwareengineering #developer #python #heaps #priorityqueue #techeducation
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