You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: dsa-solutions/lc-solutions/3100-3199/3106- Lexicographically Smallest String After Operations With Constraint.md
+8-8Lines changed: 8 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -30,23 +30,23 @@ string `t` you can get after some changes, such that `distance(s, t) <= k`.
30
30
31
31
**Example 1:**
32
32
33
-
**Input:** s = "zbbz", k = 3
33
+
**Input:**`s = "zbbz"`, `k = 3`
34
34
35
35
**Output:** "aaaz"
36
36
37
37
**Explanation:**
38
38
39
-
Change s to "aaaz". The distance between "zbbz" and "aaaz" is equal to k = 3.
39
+
Change s to "aaaz". The distance between "zbbz" and "aaaz" is equal to `k = 3`.
40
40
41
41
**Example 2:**
42
42
43
-
**Input:** s = "xaxcd", k = 4
43
+
**Input:**`s = "xaxcd"`, `k = 4`
44
44
45
45
**Output:** "aawcd"
46
46
47
47
**Explanation:**
48
48
49
-
The distance between "xaxcd" and "aawcd" is equal to k = 4.
49
+
The distance between "xaxcd" and "aawcd" is equal to `k = 4`.
50
50
51
51
52
52
### Constraints
@@ -61,7 +61,7 @@ The distance between "xaxcd" and "aawcd" is equal to k = 4.
61
61
62
62
## 1. Conversion to Character Array:
63
63
64
-
char[] result = s.toCharArray();: This line converts the input string s into a character array named result. This array will hold the modified string.
64
+
char[]`result = s.toCharArray()`;: This line converts the input string s into a character array named result. This array will hold the modified string.
65
65
66
66
## 2. Iterating Through Characters:
67
67
@@ -75,11 +75,11 @@ An inner for loop iterates through all lowercase letters `char c = 'a'; c <= 'z'
75
75
-**distance(s.charAt(i), c):**
76
76
This calculates the distance between the current character s[i] and the candidate replacement character c using a separate distance function (assumed to be defined elsewhere).
77
77
78
-
-**if (distance(s.charAt(i), c) <= k):** This checks if changing the current character to c is allowed within the k limit based on the distance.
78
+
-**if `(distance(s.charAt(i), c) <= k):`** This checks if changing the current character to c is allowed within the k limit based on the distance.
79
79
80
80
**If the distance is less than or equal to k:**
81
-
- result[i] = c;: The character in the result array at position i is updated with the new character c.
82
-
- k -= distance(s.charAt(i), c);: The remaining allowed changes (k) are decremented by the distance used for this replacement.
81
+
-`result[i] = c`;: The character in the result array at position i is updated with the new character c.
82
+
-`k -= distance(s.charAt(i), c)`;: The remaining allowed changes (k) are decremented by the distance used for this replacement.
83
83
- break;: The inner loop exits as a suitable replacement has been found within the limit.
0 commit comments