Lowest Common Ancestor on an N-ary Tree
Find the lowest common ancestor on an N-ary tree.
Input: root = [1,null,2,3,4], p = 2, q = 3
Output: 1
Explanation: Both nodes 2 and 3 are direct children of the root node 1, making 1 the lowest common ancestor.
Count Anagrammatic Substrings
Count the number of anagrammatic substrings from one string present in another.
Input: s = "abab", p = "ab"
Output: [0, 1, 2]
Explanation: The substrings "ab", "ba", and "ab" starting at indices 0, 1, and 2 respectively are all anagrams of the string "ab".
Connected Components in an Undirected Graph
Determine the number of connected components in an undirected graph.
Input: n = 4, edges = [[0,1],[2,3]]
Output: 2
Explanation: The graph is split completely evenly into two distinct isolated components: nodes {0,1} and nodes {2,3}.
Continuous Subarrays Sum Equals K
Find the total number of continuous subarrays whose sum equals K.
Input: nums = [1,2,3], k = 3
Output: 2
Explanation: Both the contiguous subarray [1,2] and the single-element subarray [3] sum perfectly to the target of 3.
Find the majority element in an array.
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array.
Input: nums = [3, 2, 3]
Output: 3
Explanation: The number 3 appears 2 times, which is strictly greate…
Validate if a given tree is a valid binary search tree.
Given the root of a binary tree, determine if it is a valid binary search tree (BST). A valid BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's key, and the right subtree contains only nodes with keys greater than the node's key…
Merge two sorted arrays into one sorted array.
You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively. Merge them into a single array sorted in non-decreasing order.
Input: nums1 = [0], m = 0, nums2 = [1], n = 1
Outp…