3694. Distinct Points Reachable After Substring Removal Medium
1/**
2 * [3694] Distinct Points Reachable After Substring Removal
3 *
4 * You are given a string s consisting of characters 'U', 'D', 'L', and 'R', representing moves on an infinite 2D Cartesian grid.
5 *
6 * 'U': Move from (x, y) to (x, y + 1).
7 * 'D': Move from (x, y) to (x, y - 1).
8 * 'L': Move from (x, y) to (x - 1, y).
9 * 'R': Move from (x, y) to (x + 1, y).
10 *
11 * You are also given a positive integer k.
12 * You must choose and remove exactly one contiguous substring of length k from s. Then, start from coordinate (0, 0) and perform the remaining moves in order.
13 * Return an integer denoting the number of distinct final coordinates reachable.
14 *
15 * <strong class="example">Example 1:
16 * <div class="example-block">
17 * Input: <span class="example-io">s = "LUL", k = 1</span>
18 * Output: <span class="example-io">2</span>
19 * Explanation:
20 * After removing a substring of length 1, s can be "UL", "LL" or "LU". Following these moves, the final coordinates will be (-1, 1), (-2, 0) and (-1, 1) respectively. There are two distinct points (-1, 1) and (-2, 0) so the answer is 2.
21 * </div>
22 * <strong class="example">Example 2:
23 * <div class="example-block">
24 * Input: <span class="example-io">s = "UDLR", k = 4</span>
25 * Output: <span class="example-io">1</span>
26 * Explanation:
27 * After removing a substring of length 4, s can only be the empty string. The final coordinates will be (0, 0). There is only one distinct point (0, 0) so the answer is 1.
28 * </div>
29 * <strong class="example">Example 3:
30 * <div class="example-block">
31 * Input: <span class="example-io">s = "UU", k = 1</span>
32 * Output: <span class="example-io">1</span>
33 * Explanation:
34 * After removing a substring of length 1, s becomes "U", which always ends at (0, 1), so there is only one distinct final coordinate.
35 * </div>
36 *
37 * Constraints:
38 *
39 * 1 <= s.length <= 10^5
40 * s consists of only 'U', 'D', 'L', and 'R'.
41 * 1 <= k <= s.length
42 *
43 */
44pub struct Solution {}
45
46// problem: https://leetcode.com/problems/distinct-points-reachable-after-substring-removal/
47// discuss: https://leetcode.com/problems/distinct-points-reachable-after-substring-removal/discuss/?currentPage=1&orderBy=most_votes&query=
48
49// submission codes start here
50
51impl Solution {
52 pub fn distinct_points(s: String, k: i32) -> i32 {
53 0
54 }
55}
56
57// submission codes end
58
59#[cfg(test)]
60mod tests {
61 use super::*;
62
63 #[test]
64 fn test_3694() {
65 }
66}
67Back
© 2026 bowen.ge All Rights Reserved.