# my-dsa-coding-concept-collection-1 Formally, the next element of nums[i] is nums[(i + 1) % n] and the previous element of nums[i] is nums[(i - 1 + n) % n]. fill arrays-> 00048_blank Topics: 1. Sorting------------------- 2. Array 3. Strings 4. Sliding window and two pointer 5. Greedy 6. Heap/Priority Queue 7. Stack and Queue and Dequeue and Monotonic Stack 8. Binary Search----------------- 9. Recursion--------------------------- 10. DP 11. Graph 12. Binary Tree 13. Binary Search Tree------------------ 14. LinkedList 15. Trie 16. Bit Manipulation---------------- 17. Math Platforms used: 0. https://takeuforward.org 1. leetcode 2. geeksforgeeks 3. udemy pratik narang course 4. neetcode 5. interview bit 6. code forces 7. code 360 naukri coding ninjas 8. spoj 9. codeforces https://codeforces.com/blog/entry/21344 Think : If n ≤ 12, the time complexity can be O(n!). If n ≤ 25, the time complexity can be O(2^n). If n ≤ 100, the time complexity can be O(n^4). If n ≤ 500, the time complexity can be O(n^3). If n ≤ 10^4, the time complexity can be O(n^2). If n ≤ 10^6, the time complexity can be O(n log n). If n ≤ 10^8, the time complexity can be O(n). If n > 10^8, the time complexity can be O(log n) or O(1). think nlogn => sorting , binary search, heap Revisit: Array: 12 : priority queue TO DO: https://www.spoj.com/problems/classical/ https://www.spoj.com/problems/classical/sort=0,start=3950 https://www.geeksforgeeks.org/smallest-difference-pair-values-two-unsorted-arrays/ https://www.geeksforgeeks.org/kth-smallest-largest-element-in-unsorted-array/?ref=ml_lbp https://leetcode.com/problems/course-schedule/description/ cycle in directed graph https://leetcode.com/problems/number-of-subsequences-that-satisfy-the-given-sum-condition/ sliding window do 19 20 21 22 23 greedy 19 20 32, 36, 45, 47, 48, 49 string : 18 onwards kth permutation sequence Knapsack Problems 3 types: 1. Greedy - Fractional knapsack - price per unit - https://www.geeksforgeeks.org/problems/knapsack-with-duplicate-items4201/1?utm_source=youtube&utm_medium=collab_striver_ytdescription&utm_campaign=knapsack-with-duplicate-items 2. DP - 0 1 knapsack 3. DP - Unbounded Knapsack From 27 June 2024, coding in java, array 38 to replace a character in a string String s="Hello"; System.out.println(s.substring(0,4)+"#"+s.substring(5)); StringBuilder sb = new StringBuilder(); sb.append("Hello"); sb.reverse(); System.out.println(sb.reverse().toString()); sb.setCharAt(0,'h'); System.out.println(sb.toString()); char[] chars = sb.toString().toCharArray(); chars[1] = 'a'; String str = new String(chars); System.out.println(str); Integer.MIN_VALUE; Integer.MAX_VALUE; Long.MIN_VALUE; Long.MAX_VALUE; Double.MIN_VALUE; Double.MAX_VALUE; Integer.intValue() or doubleValue() .equals() or compareTo()[-1,0,1] to compare wrapper classes Priority Queue min PQ: PriorityQueue<Integer> pQueue = new PriorityQueue<Integer>(); max PQ: PriorityQueue<Integer> pQueue = new PriorityQueue<Integer>(Collections.reverseOrder()); for (int key : hm.keySet()) { int freq = hm.get(key); Map<Character, Integer> map = new HashMap<>(); for (Character key : map.keySet()) { System.out.println("Key: " + key + " Value: " + map.get(key)); } map.values() for (Map.Entry<Character, Integer> entry : map.entrySet()) { System.out.println("Key: " + entry.getKey() + ", Value: " + entry.getValue()); } Set<Integer> entitySet = new HashSet<>(); for (Integer i : entitySet) { System.out.println("Entity name: " + i); } if (set.contains("A")) Note : Java Pair class is from javafx if u cant import from import javafx.util.Pair; then use the following: Queue<AbstractMap.SimpleEntry<Node, Integer>> queue = new LinkedList<>(); Collections.reverse();//pass list list.add(0,n); ArrayList<Integer> arrayList = new ArrayList<>(Arrays.asList(-1)); ArrayList<Integer> arrayList = new ArrayList<>(Arrays.asList(new Integer[]{1, 2, 3})); ArrayList<Integer> ans = new ArrayList<>(set); ans.toArray(new int[ans.size()][]) list.stream().mapToInt(i -> i).toArray(); list.stream().mapToLong(i -> i).toArray(); list.stream().mapToDouble(i -> i).toArray(); List<String> list = new LinkedList<>(); list.add("a"); list.add("b"); List<Pair> l = list.stream().map(s -> new Pair(s)).collect(Collectors.toList()); List<Pair> l = list.stream().map(s -> new Pair(s)).toList(); //Java11 or 17 Set<Pair> l = list.stream().map(s -> new Pair(s)).collect(Collector.toSet()); commonSet.retainAll(currentSet); class Pair { String s; Pair(String s) { this.s = s; } } ArrayList<String> cars = new ArrayList<String>(); // Create an ArrayList object cars.add("Volvo"); cars.add("BMW"); cars.get(0); cars.set(0, "Opel"); cars.remove(0); cars.clear(); cars.size(); Arrays.sort(cars); Collections.sort(cars); putAll() put() putIfAbsent() containsKey() all add set get method are on LinkedList or ArrayList or any List objects Fetching test cases: import java.util.ArrayList; import java.util.Scanner; public class TestCasesInput { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); ArrayList<ArrayList<String>> testCases = new ArrayList<>(); while (scanner.hasNextLine()) { ArrayList<String> testCase = new ArrayList<>(); String line; while (scanner.hasNextLine() && !(line = scanner.nextLine()).isEmpty()) { testCase.add(line); } if (!testCase.isEmpty()) { testCases.add(testCase); } } for (ArrayList<String> testCase : testCases) { System.out.println("Test Case:"); for (String line : testCase) { System.out.println(line); } System.out.println(); } } } import java.util.Scanner; public class MultilineInput { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Read the number of test cases int t = scanner.nextInt(); scanner.nextLine(); // Consume the newline character for (int i = 0; i < t; i++) { // Read the first line of the test case String[] line1 = scanner.nextLine().split(" "); int a = Integer.parseInt(line1[0]); int b = Integer.parseInt(line1[1]); // Read the second line of the test case String[] line2 = scanner.nextLine().split(" "); int c = Integer.parseInt(line2[0]); int d = Integer.parseInt(line2[1]); // Perform operations with the input values System.out.println("Test case " + (i + 1) + ": a = " + a + ", b = " + b + ", c = " + c + ", d = " + d); } scanner.close(); } } Binary Search Tree is a sorted data structure but heap is not