Day 109: Vector Vibes & C++ Logic 🚀 Problem 1855: Maximum Distance Between a Pair of Values Ported my Java logic to C++ today because performance is the goal. Switching languages is basically just remapping your brain's "how to get the length" function to .size(). The Strategy: • Two-Pointer Efficiency: Used two pointers to find the max gap in O(N+M) time. No nested loops, just speed. • The Logic: If nums1[i]≤nums2[j], I track the distance and move j; otherwise, I move i. • C++ Pivot: Getting comfortable with std::vector and the STL. It's all about that low-level control for the HPC path. The transition is officially in motion. Day 109—we're evolving. ⚡ #LeetCode #Cpp #TwoPointers #HPC #DailyCode
C++ Two-Pointer Efficiency for Maximum Distance Between Values
More Relevant Posts
-
🚀 LeetCode Challenge 31/50 💡 Approach: Backtracking Remember the old T9 keyboard on phones? This problem is exactly that — generate every possible letter combination from a sequence of digits using Backtracking! 🔍 Key Insight: → Map each digit (2-9) to its letters (just like a phone keypad) → Recursively build combinations digit by digit → At each step, try every letter mapped to the current digit → When index reaches end of digits → add combination to result → Backtrack by removing last character and try next letter 📈 Complexity: ✅ Time: O(4ⁿ) — at most 4 letters per digit (e.g. 7,9) ✅ Space: O(n) — recursion depth equals digits length Backtracking shines when you need ALL valid combinations — build, explore, undo, repeat! 📱 #LeetCode #DSA #Backtracking #Java #ADA #PBL2 #LeetCodeChallenge #Day31of50 #CodingJourney #ComputerEngineering #AlgorithmDesign #LetterCombinations
To view or add a comment, sign in
-
-
🚀 Day 15 / 85 Days of DSA Challenge Today’s problem was about applying range-based updates with a twist — stepping through the array using a custom interval (k) and applying modular multiplication. 💡 Key Learnings: Handling queries with non-contiguous updates (i += k pattern) Importance of modulo arithmetic to prevent overflow Final aggregation using bitwise XOR 🔍 Approach: For each query [l, r, k, v]: Start from index l Jump k steps each time Multiply elements by v (mod 1e9+7) Finally, compute XOR of the modified array. ⚡ This problem highlights how brute-force works but may need optimization for large constraints. Consistency > Perfection 💯 85 Days Challenge — Let’s go! 🔥 #DSA #CodingChallenge #Java #ProblemSolving #100DaysOfCode #LearningJourney
To view or add a comment, sign in
-
-
Beyond std::thread: The C++20 Multithreading Revolution. -------------------------------------- C++20 represents a watershed moment for multithreading in the language. While C++11 gave us a solid foundation with std::thread, mutexes, and condition variables, C++20 has addressed many of the pain points that made concurrent programming error-prone and verbose. The headline feature—std::jthread—brings automatic resource management and standardized thread cancellation to the table. But the story doesn't end there: new synchronization primitives (std::latch, std::barrier, std::counting_semaphore), atomic wait/notify operations, and synchronized output streams collectively transform how we write robust, maintainable concurrent code. Read more ... https://lnkd.in/daj3hUNU
To view or add a comment, sign in
-
-
Day 84 of My DSA Journey Today’s problem: Counting Bits Given a number n, the task is to return an array where each index i contains the number of 1’s in the binary representation of i. 🔍 Example: Input: n = 5 Output: [0, 1, 1, 2, 1, 2] 💡 Key Insight: Instead of counting bits every time, we reuse previous results: i >> 1 → removes last bit i & 1 → checks if last bit is 1 So, 👉 ans[i] = ans[i >> 1] + (i & 1) ⚡ This reduces time complexity to O(n) (single pass!) 📈 What I learned today: Dynamic Programming can simplify repeated computations Bit manipulation makes problems faster and cleaner Small patterns can lead to big optimizations #Day84 #DSA #Java #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 102: The Two-Finger Typing Grind ⌨️✌️ Problem 1320: Minimum Distance to Type a Word Today’s solve was about minimizing movement on a 6×5 keyboard layout. The Strategy: • Optimization via Savings: Instead of just calculating distance, I used Dynamic Programming to find the maximum "cost saved" by utilizing a second finger. • Efficient DP State: dp[c] tracks the max distance saved with the second finger at character c, allowing me to find the optimal path in a single pass. By focusing on "distance saved" rather than "total cost," the logic becomes much faster and cleaner. Day 102—keep optimizing. 🚀 #LeetCode #Java #DynamicProgramming #Algorithms #DailyCode
To view or add a comment, sign in
-
-
used the c++ and c# to solve the same problem. 500 files , imported parallel, parsed and searched for some math data and calculations then each file returned an output and 500 outputs sorted and exported. used similar math 3rd parties for that. but for parallelism own stuff of the Langs. parallelfor for c# and threadpool for c++. c# gave me 2x better perf. no need to argue here about "my impl was good or bad" . it was a standard stuff I randomly do with c++ but first time c#. to be honest this was a good lesson. don't trust propaganda about langs so much. use best Lang for best task. btw this is not the first time I came across this. so that propaganda about rust c++ stuff is a little smelly.
To view or add a comment, sign in
-
🖤 Day 44 of Solving DSA : Today, I implemented a solution to generate Pascal’s Triangle, a classic problem that helps strengthen problem-solving and array manipulation skills. 🔺 What is Pascal’s Triangle? It is a triangular array where: The first and last elements of each row are always 1 Every middle element is the sum of two elements from the previous row Example: [1] [1, 1] [1, 2, 1] [1, 3, 3, 1] 💡 Approach I Used: 1️⃣ Initialize Result List Create a list to store all rows of the triangle. 2️⃣ Iterate for Each Row Loop from 0 to numRows - 1 to build each row. 3️⃣ Set First and Last Elements Each row starts and ends with 1. 4️⃣ Calculate Middle Elements Use values from the previous row: 👉 current[j] = prev[j-1] + prev[j] 5️⃣ Store Each Row Add the constructed row to the result list. #DSA #java #100dayschallenge #leetcode #consistency
To view or add a comment, sign in
-
-
Some problems become much easier when you reframe the question. 🚀 Day 107/365 — DSA Challenge Solved: Minimum Operations to Reduce X to Zero Problem idea: We need to remove elements from the left or right so that their sum equals x, with minimum operations. Efficient approach: Instead of removing elements, think in reverse: 👉 Find the longest subarray with sum = totalSum − x Steps: 1. Calculate total sum of the array 2. Set target = totalSum − x 3. Find the longest subarray with sum = target using sliding window 4. Result = total length − longest subarray length This converts the problem into a familiar sliding window problem. ⏱ Time: O(n) 📦 Space: O(1) Day 107/365 complete. 💻 258 days to go. Code: https://lnkd.in/dad5sZfu #DSA #Java #SlidingWindow #LeetCode #LearningInPublic
To view or add a comment, sign in
-
-
🚀 Day 128/500 – DSA LeetCode Challenge Today I solved problems focused on circular arrays and greedy logic. ✅ Closest Target in Circular Array – Used linear scan + circular distance calculation to find the minimum steps. TC: O(n) | SC: O(1) ✅ Partitioning Into Minimum Number of Deci-Binary Numbers – Applied a greedy observation that the answer is the maximum digit in the string. TC: O(n) | SC: O(1) 💡 Key Learning: Sometimes the best solution comes from identifying the core mathematical insight, not complex logic. 👉 Day 128/500 #DSA #Java #500DaysChallenge #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
✨ extern "C": Use C++ with C extern "C", is a powerful feature that allows C programs to be able to call functions written in C++. Learn more about how this exactly works and how to use it. https://lnkd.in/ghmTHS7i #CProgramming #Development #CPP
To view or add a comment, sign in
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