404. Sum of Left Leaves Leetcode Solution

Leetcode Solutions

Sum of Left Leaves Leetcode Solution Difficulty: Easy Topics: Tree, Depth-First Search, Breadth-First Search, Binary Tree Given the root of a binary tree, return the sum of all left leaves. A leaf is a node with no children. A left leaf is a leaf that is the left child of another node. Example 1: Input: […]

402. Remove K Digits Leetcode Solution

Leetcode Solutions

402. Remove K Digits Leetcode Solution Difficulty: Medium Topics: String, Stack, Greedy, Monotonic Stack Given string num representing a non-negative integer num, and an integer k, return the smallest possible integer after removing k digits from num. Example 1: Input: <code>num = “1432219”, k = 3 Output: <code>“1219” Explanation: <code>Remove the three digits 4, 3, […]

386. Lexicographical Numbers Leetcode Solution

Leetcode Solutions

Lexicographical Numbers Leetcode Solution Difficulty: Medium Topics: Depth-First Search, Trie Given an integer n, return all the numbers in the range [1, n] sorted in lexicographical order. You must write an algorithm that runs in O(n) time and uses O(1) extra space. Example 1: Input: n = 13 Output: [1,10,11,12,13,2,3,4,5,6,7,8,9] Example 2: Input: n = […]

350. Intersection of Two Arrays II Leetcode Solution

Leetcode Solutions

Intersection of Two Arrays II Leetcode Solution Difficulty: Easy Topics: Array, Hash Table, Two Pointers, Binary Search, Sorting Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must appear as many times as it shows in both arrays, and you may return the result in any […]

344. Reverse String Leetcode Solution

Leetcode Solutions

Reverse String Leetcode Solution Difficulty: Easy Topics: Two Pointers, String Write a function that reverses a string. The input string is given as an array of characters s. You must do this by modifying the input array in-place with O(1) extra memory. Example 1: Input: s = [“h”,”e”,”l”,”l”,”o”] Output: [“o”,”l”,”l”,”e”,”h”] Example 2: Input: s = […]

330. Patching Array Leetcode Solution

Leetcode Solutions

330. Patching Array Difficulty: Hard Topics: Array, Greedy Welcome to our Leetcode Solution. Given a sorted integer array nums and an integer n, add/patch elements to the array such that any number in the range [1, n] inclusive can be formed by the sum of some elements in the array. Return the minimum number of […]

310. Minimum Height Trees Leetcode Solution

Leetcode Solutions

310. Minimum Height Trees Difficulty: Medium Topics: Depth-First Search, Breadth-First Search, Graph, Topological Sort A tree is an undirected graph in which any two vertices are connected by exactly one path. In other words, any connected graph without simple cycles is a tree. Given a tree of n nodes labelled from 0 to n – […]

273. Integer to English Words Leetcode Solution

Leetcode Solutions

Integer to English Words Leetcode Solution Hard Topics : Math, String, Recursion Convert a non-negative integer num to its English words representation. Example 1: Input: num = 123 Output: “One Hundred Twenty Three” Example 2: Input: num = 12345 Output: “Twelve Thousand Three Hundred Forty Five” Example 3: Input: num = 1234567 Output: “One Million […]

264. Ugly Number II Leetcode Solution

Leetcode Solutions

Ugly Number II Leetocde Solution Difficulty: Medium Topics: Hash Table, Math, Dynamic Programming, Heap (Priority Queue) An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5. Given an integer n, return the <code>nth ugly number. Example 1: Input: n = 10 Output: 12 Explanation: [1, 2, 3, 4, […]

260. Single Number III Leetcode Solution

Leetcode Solutions

260. Single Number III Leetcode Solution Difficulty: Medium Topics: Array, Bit Manipulation Given an integer array nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in any order. You must write an algorithm that […]