30 || 29 7 45 40 36 49 30 29 30 || 7 29 30 45|| 7 29 30 40 45 || 7 29 30 36 40 45 49|| 7 29 30 30 36 40 45 49|| 21 4 33 48 12 4 16 40 b i 21 4 12 48 33 4 16 40 b i 21 4 12 4 33 48 16 40 b i 21 4 12 4 16 48 33 40 b 16 4 12 4 21 48 33 40 P public class Max implements Comparator{ public int compare(Integer i1, Integer i2){ return i2-i1; } } Comparator comp; comp= new Comparator() { public int compare(Integer i1, Integer i2){ return i2-i1; } }; comp = (i1, i2) -> i2-i1; 4 5 34 14 37 28 36 14 47 1 4 4 15 7 5 9 42 50 50 37 1 4 4 15 7 5 9 42 50 50 37 4 7 5 15 37 9 50 42 50 4 7 5 15 37 9 50 42 50 Deque stack; stack = new LinkedList<>(); Queue queue; queue = new LinkedList<>(); for(int i=1; i<=5; i++) { stack.push(i); queue.add(i); } public static boolean contains(Stack s, int number) { boolean answer=false; Stack saved = new Stack(); while(!s.isEmpty()) { if(s.peek()==number) { answer = true; break; }else{ saved.push(s.pop()); } } while(!saved.isEmpty()) s.push(saved.pop()); return answer; } public static boolean hasDuplicates(int[] arr) { HashSet set = new HashSet<>(); for(int x: arr) { if(set.contains(x)) return true; else set.add(x); } return false; } PriorityQueue pq; pq = new PriorityQueue<>(); for(int x: arr) pq.add(x); for(int i=0; i 4, 4 % 30 = 4 2. " " ('A', 100)->100, 100 % 30 = 10 public static int count(BSTNode root) { if(root==null) return 0; return 1 + count(root.right) + count(root.left); } public static int max(BSTNode root) { if(root==null) throw new NoSuchElementException(); while(root.right != null) root = root.right; return root.data; } } } char[] array = {'A', 'R', 'E', 'N', 'A', 'S'}; Map map = new TreeMap<>(); for(char ch: array) { if(map.containsKey(ch)){ map.put(ch, map.get(ch)+1); }else{ map.put(ch, 1); } } for(char ch: map.keySet()) { int value = map.get(ch); System.out.println(ch + "->+ " value); } for(Map.Entry entry: map.entrySet()){ char key = entry.getKey(); int value = entry.getValue(); System.out.println(key + "->+ " value); } }