🚀 LeetCode Problem Solved – Single Number Solved the Single Number problem on LeetCode using JavaScript with an optimized bit manipulation approach. 📌 Problem Statement Given an array where every element appears twice except for one, the task is to find the element that appears only once. 💡 Approach Instead of using extra space like hash maps, I used the XOR trick. Key properties of XOR: • a ^ a = 0 (same numbers cancel each other) • a ^ 0 = a (XOR with zero keeps the number unchanged) By XORing all elements in the array: Duplicate numbers cancel out The unique number remains as the final result ⚡ Complexity 🔹 Time Complexity: O(n) – Traverse the array once 🔹 Space Complexity: O(1) – No extra data structures used #leetcode #javascript #dsa #bitmanipulation #codingpractice #softwareengineering #algorithms
Single Number Problem Solved with JavaScript Bit Manipulation
More Relevant Posts
-
rag-from-scratch by Patric Gutersohn implements RAG in plain JavaScript … no LangChain, no abstractions. Cosine similarity, recursive character splitting, BM25 + vector hybrid search, query preprocessing, all written from scratch with node-llama-cpp. The in-memory vector store makes the full pipeline traceable in a debugger. Starts at a 70-line end-to-end example and builds up to hybrid retrieval and reranking. Rare to find a repo where every function is explained instead of imported. #rag #javascript #nodellama #vectorsearch
To view or add a comment, sign in
-
-
Today I finally understood how JavaScript actually stores data in memory — and it changed the way I look at code. Earlier, I used to just write variables and functions without thinking much about what’s happening behind the scenes. But now it makes a lot more sense: Primitive values (like numbers, strings, booleans) are stored directly in memory Reference types (like arrays and objects) are stored differently — the variable holds a reference, not the actual value That’s why things like this behave unexpectedly sometimes: Copying objects doesn’t create a real copy Changing one reference can affect another Understanding this cleared up a lot of confusion I had while debugging. Still learning, but this felt like a small breakthrough Hitesh Choudhary Piyush Garg Chai Code #JavaScript #WebDevelopment #100DaysOfCode #LearningInPublic
To view or add a comment, sign in
-
-
🚀 Day 13 of #DevDSA Today’s focus: Array + Hashing Basics Solved the classic problem: Contains Duplicate (LeetCode Easy) 🔍 What I learned: Used a JavaScript Object (obj) as a hash map to track elements How hashing helps reduce time complexity drastically ⚖️ Time vs Space Tradeoff: Brute Force Time Complexity: O(n²) Space Complexity: O(1) Optimized (Using Object) Time Complexity: O(n) Space Complexity: O(n) 💡 Key takeaway: Even a simple object can act like a hash map and help achieve optimal performance. 🧠 Approach used: Traverse array once Store elements in an object (obj) If element already exists in object → duplicate found One more step forward in consistency 💪 #Day13 #LeetCode #DSA #JavaScript #CodingJourney #100DaysOfCode #Developers #LearningInPublic
To view or add a comment, sign in
-
-
Solved the Flatten a Multilevel Doubly Linked List problem using a Depth-First Search (DFS) approach in JavaScript. Key idea: Traverse the list and whenever a node contains a child pointer, recursively flatten the child list and splice it into the main list while maintaining proper prev and next connections. This problem is a great exercise in pointer manipulation and recursion. It reinforces how important it is to carefully update references when working with linked data structures. Time complexity: O(n) Space complexity: O(d) where d is the recursion depth. #DataStructures #Algorithms #LinkedList #JavaScript #DSA #CodingPractice #LeetCode #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 DSA Learning (Realization while solving Top K Frequent Elements) My initial approach was simple: 👉 Count frequency of each number using a HashMap 👉 Then compare frequency with k and push elements into a result array But then I got stuck… ❓ I tried to use .map() directly on the HashMap — and it didn’t work That’s when I realized: - Map is not an array, so array methods like .map() won’t work on it - What actually works: First convert the map into an array 👇 Array.from(map.entries()) Then: ✔️ sort by frequency ✔️ take top k ✔️ extract elements That small shift in understanding made the whole problem click 💡 #DSA #JavaScript #CodingJourney #LeetCode
To view or add a comment, sign in
-
-
Implemented an efficient solution to the Dutch National Flag problem in JavaScript, sorting an array of 0s, 1s, and 2s in a single pass using the three-pointer approach. Achieved optimal O(n) time complexity with constant O(1) space, demonstrating in-place array manipulation and clean pointer logic. #JavaScript #DSA #Algorithms #Coding #ProblemSolving #LeetCode
To view or add a comment, sign in
-
-
Built an efficient LRU Cache from scratch using JavaScript. Key highlights of the implementation: Designed a custom Doubly Linked List for O(1) insertions and deletions Used a HashMap to achieve constant-time access Ensured optimal eviction strategy by always removing the least recently used node Maintained strict O(1) time complexity for both get and put operations Performance: Runtime: 102 ms (faster than ~57% of submissions) Memory: 113.67 MB This problem reinforced how combining data structures (HashMap + DLL) leads to highly optimized systems — a pattern widely used in real-world caching systems like databases and browsers. Continuing to focus on writing clean, efficient, and scalable code. #DataStructures #Algorithms #JavaScript #SystemDesign #Coding
To view or add a comment, sign in
-
-
Just solved the Binary Search problem in JavaScript. Binary Search is a great example of the Divide and Conquer approach. Instead of checking every element, the algorithm looks at the middle of a sorted array and eliminates half of the search space each step. Because the array is divided in half every time, the time complexity becomes O(log n), which makes it much faster than linear search O(n) for large datasets. Small problem, but a great reminder of how powerful algorithmic thinking can be. #JavaScript #Algorithms #BinarySearch #CodingPractice #LeetCode #SoftwareEngineering
To view or add a comment, sign in
-
shipped wyscan v1.4.0-beta today. TypeScript and JavaScript agentic systems are now fully supported, on par with Python. for context, wyscan is a static analysis tool that scans your agent codebase and surfaces AFB04 violations before they hit production. AFB04 is the unauthorized action boundary: the point where an agent executes something it was never supposed to be allowed to do. tool calls without policy gates, execution paths with no authorization check, actions that bypass the enforcement layer entirely. wyscan finds them at the code level, before your agent is ever deployed. Until now, that coverage was Python-only. if your stack was TypeScript or JavaScript - LangChain.js, Mastra, any TS/JS agent framework - you were flying blind. v1.4.0-beta closes that gap. wyscan now scans TS/JS agentic systems the same way it handles Python. same detection logic, same CEE-formatted output, same class of findings. if an unauthorized action boundary violation exists in your agent code, it surfaces, regardless of whether you're on the Python or JS/TS side. this release also fixes and upgrades several Python-side limitations from earlier versions. the output is cleaner, the detection is more accurate, and there's less noise in the results. this is beta, so there will be rough edges. but the core detection works, the findings are real, and the coverage is there. if you're building agentic systems in TS or JS and want to know what wyscan finds in your stack, now you can. https://lnkd.in/dny8Q5tF #buildinpublic #agentsecurity #aiagents #llmsecurity #opensource #wyscan #plarix #typescript #javascript #agentic
To view or add a comment, sign in
-
-
Day 66 | JavaScript Loops & Array Iteration Today I practiced JavaScript loops and working with arrays of objects🧑🏻💻 - What I Worked On: •Iterated through array of objects using for loop •Printed all elements and accessed object properties like loc •Used loop with step increment (i += 2) to print alternate values •Practiced reverse counting using for and while loops •Used forEach() for cleaner array iteration 💡 Key Learning: •Arrays of objects are very common in real-world applications •Loop conditions must be handled carefully (i < length vs <= length) •forEach() is simple and readable for iteration •Multiple ways to loop → choose based on requirement Takeaway: Mastering loops is key to handling data efficiently in JavaScript Consistency is improving logic step by step #Day66 #JavaScript #Loops #Arraylteration #ProblemSolving #CodingJourney #10000Coders #WebDevelopment #SravanKumarSir
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