You are given a string s consisting of the characters 'U', 'D', 'L', and 'R', which represent moves on an infinite 2D grid:
• 'U': Move up → (x, y + 1)
• 'D': Move down → (x, y - 1)
• 'L': Move left → (x - 1, y)
• 'R': Move right → (x + 1, y)
You are also given an integer k, which represents the length of a contiguous substring that you must remove exactly once from s.
After removing the substring, you start at coordinate (0, 0) and perform all the remaining moves in order.
Your task is to return the number of distinct final coordinates you can reach after trying all possible substring removals of length k.
Input: s = "URUL", k = 2
Output: 2
Input: s = "LRUD", k = 3
Output: 2
Accepted:
Submission: