Furthest point from origin Thought process: We’re given a string with 'L', 'R', and '_'. 'L' → move left 'R' → move right '_' → can be either left or right 🤔 So the key idea is: the final distance mainly depends on how we use '_'. To maximize distance, we should move all '_' in the direction that already has more moves (left or right). This way, the gap increases as much as possible. So, the ans becomes: abs(lCnt - rCnt) + underscore_cnt #programming #problemSolving #coding #developers #softwareengineering #DSA #algorithms
Maximizing Distance with Underscores in DSA
More Relevant Posts
-
Cycle Sort is not just another sorting algorithm, it is provably impossible to do fewer writes. Period. Cycle Sort follows where each element belongs, places it, picks up the displaced one, and follows that element. It continues chain after chain until every cycle closes. This is group theory disguised as a sorting algorithm. By minimizing writes to memory, Cycle Sort achieves the theoretical lower bound, making it optimal for scenarios where write operations are expensive, such as flash memory or EEPROM storage. Every element moves directly to its final position with no unnecessary swaps, proving that sometimes the most elegant solution is also the most mathematically efficient. #CycleSort #Programming #CodingLife #TechEducation #Algorithms #SortingAlgorithm #GroupTheory #OptimalAlgorithm #MemoryEfficient #ComputerScience #WriteOptimized #AlgorithmDesign #Coding #Developer #TechLearning #DataStructures #ProgrammingLife #CodeSmart #AlgorithmArt #ProvablyOptimal
To view or add a comment, sign in
-
SOLID PRINCIPLE PART - 8 WHAT IS LSP OR MEANING OF ‘L’? L — Liskov Substitution Principle 👇 👉 Child class should behave like parent ❌ Example: Bird → Fly() Ostrich → cannot fly ❌ 👉 Breaks system ✔ Fix: Separate flying behavior 👉 Correct inheritance = stable system 🔔 Follow me for more: TechClarityWithVijay 👤 Vijay Narayan Mishra https://lnkd.in/gaWaDqZj #dotnet #softwareengineering #backenddeveloper #cleanarchitecture #coding #developers #systemdesign #TechClarityWithVijay
To view or add a comment, sign in
-
-
Explain about a Depth-First Search (DFS)? Depth-First Search (DFS) is a graph traversal algorithm that explores as deep as possible along each branch before backtracking, utilizing a stack (or recursion) to keep track of nodes. It starts at a designated root node, marks nodes as visited to avoid cycles, and recursively visits unvisited neighbors. #DepthFirstSearch #DFS #DataStructures #Algorithms #GraphTheory #TreeTraversal #Coding #Programming #ComputerScience #Developer #SoftwareEngineering #LearnToCode #CodingInterview #ProblemSolving #AlgorithmDesign #DSA
To view or add a comment, sign in
-
-
Binary tree right side view Approach: - Keep a level variable - If level == result.size(), add current node (first node of that level) - Traverse right first, then left Time: O(n) Space: O(h) (worst: O(n), best: O(log n)) #Algorithms #DSA #LeetCode #coding #Programming
To view or add a comment, sign in
-
-
51 of #100DaysOfCode Solved LeetCode 739 — Daily Temperatures using the Monotonic Stack approach 🔥 💡 Approach: Instead of checking every future day (which would be inefficient), I used a stack to store indices of temperatures in decreasing order. Traverse the array If the current temperature is higher than the one at the stack’s top, we’ve found the next warmer day Pop the index and calculate the difference Push the current index into the stack This ensures each element is processed only once — making it super efficient ⚡ ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(n) #leetcode #coding #dsa #cpp #programming #developers #tech #interviewprep
To view or add a comment, sign in
-
-
Solved today’s LeetCode Daily and it made me pause 👇 “XOR After Range Multiplication Queries I” At first glance, it looks like: Segment Tree? Lazy Propagation? Some heavy optimization? 🤯 But the reality? Sometimes… brute force wins. --- Given constraints were small. And that completely changes the game. So instead of overengineering: ✔️ Just simulate each query ✔️ Jump with k steps ✔️ Apply multiplication (mod 1e9+7) ✔️ Take final XOR And that’s it. --- The interesting part 👇 As developers, we are trained to think: “Optimize first” But problems like this remind us: 👉 Understand constraints before choosing approach Because honestly, A simple O(n * q) solution can beat an overcomplicated design any day. --- What I learned today: • Not every problem needs advanced DS • Constraints are part of the problem statement for a reason • Simplicity is underrated --- Consistency check ✅ One more problem done. --- Curious 👇 Comment your approach. #LeetCode #DSA #Programming #Coding #Developers #ProblemSolving #Rust
To view or add a comment, sign in
-
-
Understanding the path to the solution. I recently solved LeetCode 62: Unique Paths. While the problem seems simple at first glance, it’s a perfect example of how Dynamic Programming can optimize a solution from exponential time to linear time. The core idea: The number of ways to reach any cell is simply the sum of ways to reach the cell above it and the cell to its left. Seeing that "Accepted" screen with a 0ms runtime is always a great feeling! #SoftwareEngineering #DynamicProgramming #Coding #LeetCodeDaily
To view or add a comment, sign in
-
-
Every developer has seen this at least once 😅 A bug shows up in production. Everyone is stressed. Time is ticking. Then someone says... “Don’t worry, I fixed it.” 👀 You check the code and realize, the “fix” was just commenting it out. No error. No crash. No feature either 😂 It’s funny, but it’s also a lesson: Fixing a bug isn’t about hiding the problem, it’s about understanding why it happened in the first place. Because “no code = no bug” works. until someone asks, “why isn’t this working anymore?” 😭 #coding #dsa #algorithms #programming #developers #learncoding
To view or add a comment, sign in
-
-
I came across an interesting thought today: Deleting 1 million rows from a table can take seconds (or more)… But dropping that same table? Almost instant. As developers, we use these operations all the time—but the difference in performance is huge. Why does this happen? #programming #interviewQuestion #coding #softwareEngineering
To view or add a comment, sign in
-
-
Solved a great DP problem today: Count Binary Strings Without Consecutive 1’s. Given a length n, the task is to count all distinct binary strings such that no two 1s are adjacent. Example: n = 3 → 000, 001, 010, 100, 101 → 5 n = 2 → 00, 01, 10 → 3 The key insight: 1. Strings ending with 0 can be formed by appending 0 to all valid strings of previous length. 2. Strings ending with 1 can only be formed by appending 1 to strings that previously ended with 0. This leads to a simple DP relation: 1. zero[i] = zero[i-1] + one[i-1] 2. one[i] = zero[i-1] So the pattern follows a Fibonacci-style sequence, and the problem can be solved in: O(n) time and O(1) space I enjoy how problems like this look simple at first, but the right state definition makes them very elegant. #DataStructures #Algorithms #DynamicProgramming #Coding #ProblemSolving #Cpp #Programming #SoftwareDevelopment
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