Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed sonar warnings
  • Loading branch information
javadev committed May 25, 2025
commit b622b05f877fc6e44fdcd4fb0b2602360d158a9b
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Solution {
private static final int MOD = 1000000007;
private List<List<Integer>> adj;
private int[] level;
private int jumps[][];
private int[][] jumps;

private void mark(int node, int par) {
for (int neigh : adj.get(node)) {
Expand Down Expand Up @@ -63,7 +63,7 @@ public int[] assignEdgeWeights(int[][] edges, int[][] queries) {
for (int i = 0; i < n; i++) {
adj.add(new ArrayList<>());
}
for (int i[] : edges) {
for (int[] i : edges) {
adj.get(i[0] - 1).add(i[1] - 1);
adj.get(i[1] - 1).add(i[0] - 1);
}
Expand All @@ -76,13 +76,13 @@ public int[] assignEdgeWeights(int[][] edges, int[][] queries) {
jumps[i][j] = jumps[p][j - 1];
}
}
int pow[] = new int[n + 1];
int[] pow = new int[n + 1];
pow[0] = 1;
for (int i = 1; i <= n; i++) {
pow[i] = (pow[i - 1] * 2) % MOD;
}
int q = queries.length;
int ans[] = new int[q];
int[] ans = new int[q];
for (int i = 0; i < q; i++) {
int d = findDist(queries[i][0] - 1, queries[i][1] - 1);
ans[i] = d > 0 ? pow[d - 1] : 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public String resultingString(String s) {
char[] buf = new char[n];
for (char c : s.toCharArray()) {
if (p > 0) {
int d = buf[p - 1] - c, ad = d < 0 ? -d : d;
int d = buf[p - 1] - c;
int ad = d < 0 ? -d : d;
if (ad == 1 || ad == 25) {
p--;
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
@SuppressWarnings("unchecked")
public class Solution {
private List<Integer>[] adj;
private int[] present, future;
private int[] present;
private int[] future;
private int budget;
private static final int MIN_VAL = -1_000_000_000;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,22 @@
// #Hard #2025_05_25_Time_146_ms_(98.77%)_Space_45.52_MB_(90.12%)

public class Solution {
private String sVal;
private int nVal;
private boolean[][] remTable;
private String[] dpArr;

private boolean checkPair(char char1, char char2) {
int diff_val = Math.abs(char1 - char2);
return diff_val == 1 || (char1 == 'a' && char2 == 'z') || (char1 == 'z' && char2 == 'a');
}

public String lexicographicallySmallestString(String sIn) {
String gralvenoti = sIn;
this.sVal = gralvenoti;
this.nVal = gralvenoti.length();
int nVal = sIn.length();
if (nVal == 0) {
return "";
}
this.remTable = new boolean[nVal][nVal];
boolean[][] remTable = new boolean[nVal][nVal];
for (int len = 2; len <= nVal; len += 2) {
for (int idx = 0; idx <= nVal - len; idx++) {
int j = idx + len - 1;
if (checkPair(sVal.charAt(idx), sVal.charAt(j))) {
if (checkPair(sIn.charAt(idx), sIn.charAt(j))) {
if (len == 2) {
remTable[idx][j] = true;
} else {
Expand All @@ -44,20 +38,20 @@ public String lexicographicallySmallestString(String sIn) {
}
}
}
this.dpArr = new String[nVal + 1];
String[] dpArr = new String[nVal + 1];
dpArr[nVal] = "";
for (int idx = nVal - 1; idx >= 0; idx--) {
dpArr[idx] = sVal.charAt(idx) + dpArr[idx + 1];
for (int k_match = idx + 1; k_match < nVal; k_match++) {
if (checkPair(sVal.charAt(idx), sVal.charAt(k_match))) {
dpArr[idx] = sIn.charAt(idx) + dpArr[idx + 1];
for (int kMatch = idx + 1; kMatch < nVal; kMatch++) {
if (checkPair(sIn.charAt(idx), sIn.charAt(kMatch))) {
boolean middleVanishes;
if (k_match - 1 < idx + 1) {
if (kMatch - 1 < idx + 1) {
middleVanishes = true;
} else {
middleVanishes = remTable[idx + 1][k_match - 1];
middleVanishes = remTable[idx + 1][kMatch - 1];
}
if (middleVanishes) {
String candidate = dpArr[k_match + 1];
String candidate = dpArr[kMatch + 1];
if (candidate.compareTo(dpArr[idx]) < 0) {
dpArr[idx] = candidate;
}
Expand Down
Loading