Solved! Leetcode 2352. Equal Row and Column Pairs

source: https://leetcode.com/problems/equal-row-and-column-pairs/description/ Equal Row and Column Pairs Description Given a 0-indexed n x n integer matrix grid, return the number of pairs (ri, cj) such that row ri and column cj are equal. A row and column pair are considered equal if they contain the same elements in the same order (i.e., an equal array). ...

Solved! Leetcode 1485. Clone Binary Tree With Random Pointer

source: https://leetcode.com/problems/clone-binary-tree-with-random-pointer/description/ Clone Binary Tree With Random Pointer A binary tree is given such that each node contains an additional random pointer which could point to any node in the tree or null. Return a deep copy of the tree. The tree is represented in the same input/output way as normal binary trees where each ...

Solved! Leetcode 438: Find All Anagrams in a String

source: https://leetcode.com/problems/find-all-anagrams-in-a-string/description/ An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. Given two strings s and p, return an array of all the start indices of p’s anagrams in s. You may return the answer in any order. ...

Solved! Leetcode 734: Sentence Similarity

Sentence Similarity We can represent a sentence as an array of words, for example, the sentence "I am happy with leetcode" can be represented as arr = ["I","am",happy","with","leetcode"]. Given two sentences sentence1 and sentence2 each represented as a string array and given an array of string pairs similarPairs where similarPairs[i] = [xi, yi] indicates that ...

Leetcode 2244: Minimum Rounds to Complete All Tasks

You are given a 0-indexed integer array tasks, where tasks[i] represents the difficulty level of a task. In each round, you can complete either 2 or 3 tasks of the same difficulty level. Return the minimum rounds required to complete all the tasks, or -1 if it is not possible to complete all the tasks. Example 1: <strong>Input:</strong> tasks = [2,2,3,3,2,4,4,4,4,4] <strong>Output:</strong> 4 <strong>Explanation:</strong> To complete ...

Leetcode 379: Design Phone Directory

Design a phone directory that initially has maxNumbers empty slots that can store numbers. The directory should store numbers, check if a certain slot is empty or not, and empty a given slot. Implement the PhoneDirectory class: PhoneDirectory(int maxNumbers) Initializes the phone directory with the number of available slots maxNumbers.int get() Provides a number that ...

Null Keys or values in HashMap/Hashtable 4

Can java.util.HashMap store null key/value pair? Yes it can, However only one null key is allowed, but can store many null values against non-null keys   Example public class HashMapTest { public static void main(String args[]) { HashMap h = new HashMap(); h.put(null,null); h.put(null, "1"); h.put("1", null); h.put("1", "1"); h.put("2", null); System.out.println(h.get(null).toString()); System.out.println(h.get("1")); System.out.println(h.get("2")); } ...

Hashmap and Hashtable

The HashMap class is roughly equivalent to Hashtable, except that it is non synchronized and permits nulls. (HashMap allows null values as key and value whereas Hashtable doesn’t allow nulls). However, HashMap can be synchronized using Map m = Collections.synchronizeMap(hashMap); Hashtable and HashMap are member of the Java Collections Framework (since Java 2 platform v1.2, ...