comments for bob solutions

This commit is contained in:
2026-04-19 00:02:15 -05:00
parent ee7b6b1581
commit fcda1c6e25
5 changed files with 30 additions and 26 deletions

View File

@@ -2,6 +2,7 @@
import java.util.Scanner; import java.util.Scanner;
// Full solved correct solution
public class DealEmOut { public class DealEmOut {
public static void main(String[] args) { public static void main(String[] args) {
Scanner sc = new Scanner(System.in); Scanner sc = new Scanner(System.in);

View File

@@ -6,6 +6,7 @@ import java.io.InputStreamReader;
import java.util.Arrays; import java.util.Arrays;
import java.util.StringTokenizer; import java.util.StringTokenizer;
//Incomplete Not Working
public class DontTestMe { public class DontTestMe {
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
@@ -17,16 +18,12 @@ public class DontTestMe {
Test[] ar = new Test[N]; Test[] ar = new Test[N];
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine()); st = new StringTokenizer(br.readLine());
ar[i] = new Test(Integer.parseInt(st.nextToken()),Integer.parseInt(st.nextToken()),Double.parseDouble(st.nextToken())); ar[i] = new Test(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()),
Double.parseDouble(st.nextToken()));
} }
Arrays.sort(ar, (a1, a2) -> a1.compareTo(a2)); Arrays.sort(ar, (a1, a2) -> a1.compareTo(a2));
} }
} }
@@ -45,8 +42,10 @@ class Test{
public int compareTo(Object o) { public int compareTo(Object o) {
Test t = (Test) o; Test t = (Test) o;
if (this.weight > t.weight) return 1; if (this.weight > t.weight)
else if (this.weight < t.weight) return -1; return 1;
else if (this.weight < t.weight)
return -1;
return 0; return 0;
} }
} }

View File

@@ -7,11 +7,13 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.StringTokenizer; import java.util.StringTokenizer;
//Nearly correct solution...one/two bugs passed most testcases
public class Island { public class Island {
static int N, M; static int N, M;
static int[][] grid; static int[][] grid;
static boolean[][] visited; static boolean[][] visited;
static Map<Integer, Integer> islands = new HashMap<>(); static Map<Integer, Integer> islands = new HashMap<>();
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine()); StringTokenizer st = new StringTokenizer(br.readLine());
@@ -29,7 +31,8 @@ public class Island {
br.close(); br.close();
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) { for (int j = 0; j < M; j++) {
if (visited[i][j]) continue; if (visited[i][j])
continue;
if (grid[i][j] > 0) { if (grid[i][j] > 0) {
islands.put(grid[i][j], islands.getOrDefault(grid[i][j], 0) + 1); islands.put(grid[i][j], islands.getOrDefault(grid[i][j], 0) + 1);
search(grid[i][j], i, j); search(grid[i][j], i, j);
@@ -50,7 +53,8 @@ public class Island {
} }
static void search(int val, int i, int j) { static void search(int val, int i, int j) {
if (visited[i][j]) return; if (visited[i][j])
return;
visited[i][j] = true; visited[i][j] = true;
for (int dir = 0; dir < 4; dir++) { for (int dir = 0; dir < 4; dir++) {
switch (dir) { switch (dir) {

View File

@@ -7,6 +7,7 @@ import java.io.PrintWriter;
import java.util.PriorityQueue; import java.util.PriorityQueue;
import java.util.StringTokenizer; import java.util.StringTokenizer;
//Correct solution with too much time complexity O(n*n) fails almost every test case to time
public class MaximumAura { public class MaximumAura {
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
@@ -53,7 +54,6 @@ public class MaximumAura {
out.print((left[i] + right[i] - 1) + " "); out.print((left[i] + right[i] - 1) + " ");
} }
br.close(); br.close();
out.flush(); out.flush();

View File

@@ -5,6 +5,7 @@ import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.StringTokenizer; import java.util.StringTokenizer;
// Working but O(n*n) --> 50% of test cases fail on time complexity
public class WeightedDifference { public class WeightedDifference {
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
@@ -12,7 +13,6 @@ public class WeightedDifference {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// Write code here // Write code here
int a = Integer.parseInt(br.readLine()); int a = Integer.parseInt(br.readLine());