diff options
| author | Ali <adeadmarshal@gmail.com> | 2025-10-13 14:03:49 +0330 |
|---|---|---|
| committer | Ali <adeadmarshal@gmail.com> | 2025-10-13 14:03:49 +0330 |
| commit | 0bcccf52bb7367d0b2dedd1d4f2f79ee971e22b7 (patch) | |
| tree | 31fa02f44ab09bede0a996aa780a3bb39fb6c718 /challenge-343/deadmarshal/java | |
| parent | 35a27e16cb743acd46c1f315766530dc991ac587 (diff) | |
| download | perlweeklychallenge-club-0bcccf52bb7367d0b2dedd1d4f2f79ee971e22b7.tar.gz perlweeklychallenge-club-0bcccf52bb7367d0b2dedd1d4f2f79ee971e22b7.tar.bz2 perlweeklychallenge-club-0bcccf52bb7367d0b2dedd1d4f2f79ee971e22b7.zip | |
TWC343
Diffstat (limited to 'challenge-343/deadmarshal/java')
| -rw-r--r-- | challenge-343/deadmarshal/java/Ch1.java | 17 | ||||
| -rw-r--r-- | challenge-343/deadmarshal/java/Ch2.java | 32 |
2 files changed, 49 insertions, 0 deletions
diff --git a/challenge-343/deadmarshal/java/Ch1.java b/challenge-343/deadmarshal/java/Ch1.java new file mode 100644 index 0000000000..28047983fa --- /dev/null +++ b/challenge-343/deadmarshal/java/Ch1.java @@ -0,0 +1,17 @@ +public class Ch1 { + public static void main(String[] args) { + System.out.println(zero_friend(new int[]{4,2,-1,3,-2})); + System.out.println(zero_friend(new int[]{-5,5,-3,3,-1,1})); + System.out.println(zero_friend(new int[]{7,-3,0,2,-8})); + System.out.println(zero_friend(new int[]{-2,-5,-1,-8})); + System.out.println(zero_friend(new int[]{-2,2,-4,4,-1,1})); + } + + private static int zero_friend(int[] arr) { + int res = Integer.MAX_VALUE; + for(int e : arr) + if(Math.abs(e) < res) res = Math.abs(e); + return res; + } +} + diff --git a/challenge-343/deadmarshal/java/Ch2.java b/challenge-343/deadmarshal/java/Ch2.java new file mode 100644 index 0000000000..fe4b609d79 --- /dev/null +++ b/challenge-343/deadmarshal/java/Ch2.java @@ -0,0 +1,32 @@ +import java.util.Map; +import java.util.HashMap; + +public class Ch2 { + public void main(String[] args) { + System.out.println( + champion_team(new int[][] { { 0, 1, 1 }, { 0, 0, 1 }, { 0, 0, 0 } })); + System.out.println(champion_team(new int[][] { { 0, 1, 0, 0 }, + { 0, 0, 0, 0 }, { 1, 1, 0, 0 }, { 1, 1, 1, 0 } })); + System.out.println(champion_team(new int[][] { { 0, 1, 0, 1 }, + { 0, 0, 1, 1 }, { 1, 0, 0, 0 }, { 0, 0, 1, 0 } })); + System.out.println( + champion_team(new int[][] { { 0, 1, 1 }, { 0, 0, 0 }, { 0, 1, 0 } })); + System.out.println( + champion_team(new int[][] { { 0, 0, 0, 0, 0 }, { 1, 0, 0, 0, 0 }, + { 1, 1, 0, 1, 1 }, { 1, 1, 0, 0, 0 }, { 1, 1, 0, 1, 0 } })); + } + + private static int champion_team(int[][] grid) { + int m = 0; + Map<Integer,Integer> h = new HashMap<>(); + for(int y = 0; y < grid.length; ++y) { + for(int x = 0; x < grid[y].length; ++x) { + int w = grid[y][x] == 1 ? y : x; + h.put(w,h.getOrDefault(w,0) + 1); + if(h.get(w) > h.getOrDefault(m,0)) m = w; + } + } + return m; + } +} + |
