Author: Editorial Team
-
Problem 153: Find Minimum in Rotated Sorted Array
You are given a rotated sorted array with unique elements.Your task is to return the minimum value in this array. A rotated sorted array is formed by taking a sorted array and rotating (shifting) it some number of times. Example:Original sorted array: [0, 1, 2, 4, 5, 6, 7]After rotation: [4, 5, 6, 7, 0,…
-
Problem 797: All Paths From Source to Target
You are given a directed acyclic graph (DAG). The graph is represented as an adjacency list, where: graph[i] = list of all nodes you can go to directly from node i. Your task is to return all possible paths from node 0 (source) to node n−1 (target). Understanding the Problem Example: graph =[[1,2],[3],[3],[]] This means:…
-
Problem 260: Single Number III
You are given an integer array where every element appears exactly twice except for two elements which appear only once.Your task is to return those two unique numbers. Example: Input: [1,2,1,3,2,5]Output: [3,5]Explanation:Numbers 1 and 2 appear twice.Numbers 3 and 5 appear once. Order does not matter. Understanding the Problem This is a variation of the…
-
Problem 103: Binary Tree Zigzag Level Order Traversal
You are given the root of a binary tree.Your task is to return its level order traversal, but with a twist: Levels must alternate between left-to-right and right-to-left. This pattern is commonly called a zigzag or spiral traversal. Understanding the Problem Example tree: Expected output: [[3],[20, 9],[15, 7]] Explanation:Level 0 → left to right →…
-
Problem 79: Word Search
You are given a 2D board of characters and a word.Your task is to determine whether the word exists in the board. A word exists if it can be constructed from sequentially adjacent cells.Valid moves are only horizontal and vertical (no diagonal).The same cell cannot be used more than once. Understanding the Problem Example: Board:…
-
Problem 203: Remove Linked List Elements
Understanding the Problem A linked list consists of nodes, and each node has:value → node.valpointer → node.next Your job is to traverse the list and skip all nodes having a specific value. Example: Input: head = [1,2,6,3,4,5,6], val = 6Output: [1,2,3,4,5]Explanation: All nodes containing 6 must be removed. Key point:The node to be removed may…
-
Problem 67: Add Binary
You are given two binary strings a and b.You must return their sum, also as a binary string. Binary numbers use digits 0 and 1.Addition rules are similar to normal addition, but with base 2. Understanding the Problem Example: a = “11”b = “1”Output = “100” Explanation:11 (binary) = 31 (binary) = 13 + 1…
-
Problem 210: Course Schedule II
You are given the number of courses and a list of prerequisite pairs.Your task is to find an ordering in which you can finish all courses. This is a classic directed graph problem where each course is a node, and each prerequisite is a directed edge. If a valid ordering exists, return it.If it is…
-
Problem 395: Longest Substring with At Least K Repeating Characters
Understanding the Problem You are given a string s and an integer k.You must find the length of the longest substring where every character appears at least k times. For example: Input: s = “aaabb”, k = 3Output: 3Valid substring: “aaa” (each character frequency ≥ 3) Another example: Input: s = “ababbc”, k = 2Output:…
-
Problem 347: Top K Frequent Elements
Understanding the Problem You are given an integer array and a number K.Your task is to return the K elements that appear the most number of times in the array. Example: Input: nums = [1, 1, 1, 2, 2, 3], k = 2Output: [1, 2] Here:1 occurs 3 times2 occurs 2 times3 occurs 1 time…
