Maximizing Distance with Underscores in DSA

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

  • text

To view or add a comment, sign in

Explore content categories