class Solution { public int characterReplacement(String s, int k) { int max = 0; int res = 0; int[] arr = new int[26]; int i = 0; int j = 0; while (j < s.length()) { arr[s.charAt(j) - 'A']++; max = Math.max(max, arr[s.charAt(j) - 'A']); if (j - i + 1 - max > k) { arr[s.charAt(i) - 'A']--; i++; } res = Math.max(res, j - i + 1); j++; } return res; } }
Brute Force Approach class Solution { private boolean isValid(String s, int k) { int[] arr = new int[26]; int max = 0; for (char c : s.toCharArray()) { arr[c - 'A']++; max = Math.max(max, arr[c - 'A']); } return (s.length() - max)
Time Complexity of Brute Force Approach is 0(n^3) and Space Complexity is 0(n)
class Solution {
public int characterReplacement(String s, int k) {
int max = 0;
int res = 0;
int[] arr = new int[26];
int i = 0;
int j = 0;
while (j < s.length()) {
arr[s.charAt(j) - 'A']++;
max = Math.max(max, arr[s.charAt(j) - 'A']);
if (j - i + 1 - max > k) {
arr[s.charAt(i) - 'A']--;
i++;
}
res = Math.max(res, j - i + 1);
j++;
}
return res;
}
}
Time Complexity of Brute force approach is O(n^2).
1>1 is true? It's false 17:18 , she just copy, pasted the solution + very bad variable name choosen.
i think you have just pasted up the optimised solution , you don't have proper understanding of solution , why it is working
true, just copy-pasted, i dont know what she is explaining, just mugging up the concepts and logics
Day 17 Done✅✅
done thanks 👍
Brute Force Approach
class Solution {
private boolean isValid(String s, int k) {
int[] arr = new int[26];
int max = 0;
for (char c : s.toCharArray()) {
arr[c - 'A']++;
max = Math.max(max, arr[c - 'A']);
}
return (s.length() - max)
Done ✌✌
DAY 17 DONE