Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Distinct Points Reachable After Substring Removal

XPChallenge Points: 20
levelLevel: Medium

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.

Example 1:

Input: s = "URUL", k = 2

Output: 2

Example 2:

Input: s = "LRUD", k = 3

Output: 2

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result