diff --git a/solutions/battle-of-the-brains-2026/DealEmOut.java b/solutions/battle-of-the-brains-2026/DealEmOut.java index c171204..995ad3c 100644 --- a/solutions/battle-of-the-brains-2026/DealEmOut.java +++ b/solutions/battle-of-the-brains-2026/DealEmOut.java @@ -2,6 +2,7 @@ import java.util.Scanner; +// Full solved correct solution public class DealEmOut { public static void main(String[] args) { Scanner sc = new Scanner(System.in); diff --git a/solutions/battle-of-the-brains-2026/DontTestMe.java b/solutions/battle-of-the-brains-2026/DontTestMe.java index b46d2e6..0dd3129 100644 --- a/solutions/battle-of-the-brains-2026/DontTestMe.java +++ b/solutions/battle-of-the-brains-2026/DontTestMe.java @@ -6,8 +6,9 @@ import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; -public class DontTestMe { - public static void main(String[] args) throws IOException{ +//Incomplete Not Working +public class DontTestMe { + public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); @@ -15,38 +16,36 @@ public class DontTestMe { int N = Integer.parseInt(st.nextToken()); int H = Integer.parseInt(st.nextToken()); Test[] ar = new Test[N]; - for (int i =0; i < N; i++){ + for (int i = 0; i < N; i++) { 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)); } } -class Test{ - int hours,points; +class Test { + int hours, points; double percent; double weight; - public Test (int h, int p, double per){ + public Test(int h, int p, double per) { hours = h; points = p; percent = per; - weight = 1/(double) hours * points * percent; + weight = 1 / (double) hours * points * percent; } - public int compareTo(Object o){ + public int compareTo(Object o) { Test t = (Test) o; - if (this.weight > t.weight) return 1; - else if (this.weight < t.weight) return -1; + if (this.weight > t.weight) + return 1; + else if (this.weight < t.weight) + return -1; return 0; } } diff --git a/solutions/battle-of-the-brains-2026/Island.java b/solutions/battle-of-the-brains-2026/Island.java index 9fdf66a..3fa93d1 100644 --- a/solutions/battle-of-the-brains-2026/Island.java +++ b/solutions/battle-of-the-brains-2026/Island.java @@ -7,11 +7,13 @@ import java.util.HashMap; import java.util.Map; import java.util.StringTokenizer; +//Nearly correct solution...one/two bugs passed most testcases public class Island { static int N, M; static int[][] grid; static boolean[][] visited; static Map islands = new HashMap<>(); + public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); @@ -29,7 +31,8 @@ public class Island { br.close(); for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { - if (visited[i][j]) continue; + if (visited[i][j]) + continue; if (grid[i][j] > 0) { islands.put(grid[i][j], islands.getOrDefault(grid[i][j], 0) + 1); search(grid[i][j], i, j); @@ -50,10 +53,11 @@ public class Island { } static void search(int val, int i, int j) { - if (visited[i][j]) return; + if (visited[i][j]) + return; visited[i][j] = true; for (int dir = 0; dir < 4; dir++) { - switch(dir) { + switch (dir) { case 0: if (j + 1 < M && grid[i][j + 1] == val) { search(val, i, j + 1); diff --git a/solutions/battle-of-the-brains-2026/MaximumAura.java b/solutions/battle-of-the-brains-2026/MaximumAura.java index 7a0ce05..c126590 100644 --- a/solutions/battle-of-the-brains-2026/MaximumAura.java +++ b/solutions/battle-of-the-brains-2026/MaximumAura.java @@ -7,6 +7,7 @@ import java.io.PrintWriter; import java.util.PriorityQueue; 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 static void main(String[] args) throws IOException { @@ -53,7 +54,6 @@ public class MaximumAura { out.print((left[i] + right[i] - 1) + " "); } - br.close(); out.flush(); diff --git a/solutions/battle-of-the-brains-2026/WeightedDifference.java b/solutions/battle-of-the-brains-2026/WeightedDifference.java index 0b41e75..718de66 100644 --- a/solutions/battle-of-the-brains-2026/WeightedDifference.java +++ b/solutions/battle-of-the-brains-2026/WeightedDifference.java @@ -5,14 +5,14 @@ import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; -public class WeightedDifference { - public static void main(String[] args) throws IOException{ +// Working but O(n*n) --> 50% of test cases fail on time complexity +public class WeightedDifference { + public static void main(String[] args) throws IOException { - double t = System.currentTimeMillis(); + double t = System.currentTimeMillis(); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - // Write code here int a = Integer.parseInt(br.readLine()); @@ -42,7 +42,7 @@ public class WeightedDifference { } System.out.println(max); - System.out.println(System.currentTimeMillis()-t); + System.out.println(System.currentTimeMillis() - t); }