1. Problem Statement (Simple Explanation): You’re given an array of strings strs. You must group together all anagrams , where: Two strings are anagrams if one can be rearranged to form the other. You can return groups in any order. The order of strings inside each group doesn’t matter. 2. Examples: Example 1: Input: strs = ["eat","tea","tan","ate","nat","bat"] Groups: "bat" → ["bat"] (no anagram partners) "nat", "tan" → ["nat","tan"] "eat", "tea", "ate" → ["eat","tea","ate"] Output: [["bat"],["nat","tan"],["ate","eat","tea"]] Example 2: Input: strs = [""]` Output: [[""]] Example 3: Input: strs = ["a"] Output: [["a"]] 3. Approach – Hash Map with Canonical Key: To group anagrams, we need a way to map ...
1. Problem Statement (Simple Explanation): You’re given an n x n 2D matrix representing an image. You must rotate the image by 90° clockwise in-place , meaning: Modify the input matrix directly. Do not allocate another n x n matrix. 2. Examples: Example 1: Input: matrix = [ [1,2,3], [4,5,6], [7,8,9] ] Output (90° clockwise): [ [7,4,1], [8,5,2], [9,6,3] ] Example 2: Input: matrix = [ [5,1,9,11], [2,4,8,10], [13,3,6,7], [15,14,12,16] ] Output: [ [15,13,2,5], [14,3,4,1], [12,6,8,9], [16,7,10,11] ] 3. Approach 1 – Transpose + Reverse Each Row (Clean & Standard): A 90° clockwise rotation can be done in two in-place steps: Transpose the matrix (swap rows and columns): matrix[i][j] ↔ matrix[j][i] for i < j. After transpose, rows become columns. Reverse...