id
int64
1
2k
content
stringlengths
272
88.9k
title
stringlengths
3
77
title_slug
stringlengths
3
79
question_content
stringlengths
230
5k
question_hints
stringclasses
695 values
tag
stringclasses
618 values
level
stringclasses
3 values
similar_question_ids
stringclasses
822 values
1,545
hi guys so today we are going to do the question uh find the kth bit in the net binary string right so given two positive integers n and k the binary string s of n is formed as follows initially s of 1 is equal to 0 like a 0 string and then s of i each successive string is made of s of i minus 1 that is the previous st...
Find Kth Bit in Nth Binary String
form-largest-integer-with-digits-that-add-up-to-target
Given two positive integers `n` and `k`, the binary string `Sn` is formed as follows: * `S1 = "0 "` * `Si = Si - 1 + "1 " + reverse(invert(Si - 1))` for `i > 1` Where `+` denotes the concatenation operation, `reverse(x)` returns the reversed string `x`, and `invert(x)` inverts all the bits in `x` (`0` changes to ...
Use dynamic programming to find the maximum digits to paint given a total cost. Build the largest number possible using this DP table.
Array,Dynamic Programming
Hard
null
111
hey guys welcome back to another video and today we're going to be solving the lee code question minimum depth of a binary tree all right so we're going to be given a binary tree and we want to find its minimum depth the minimum depth is the number of nodes along the shortest path from the root node down to the nearest...
Minimum Depth of Binary Tree
minimum-depth-of-binary-tree
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. **Note:** A leaf is a node with no children. **Example 1:** **Input:** root = \[3,9,20,null,null,15,7\] **Output:** 2 **Example 2:** **Input:** root = \[2...
null
Tree,Depth-First Search,Breadth-First Search,Binary Tree
Easy
102,104
336
hello friends today let's solve palindrome pairs problem give a list of unique words return all the pairs of the distinct indexes ij in the giving list so that the concatenation of their two words i plus words j is a palindrome so the question statement is pretty simple but how to solve it the beautiful solution will b...
Palindrome Pairs
palindrome-pairs
You are given a **0-indexed** array of **unique** strings `words`. A **palindrome pair** is a pair of integers `(i, j)` such that: * `0 <= i, j < words.length`, * `i != j`, and * `words[i] + words[j]` (the concatenation of the two strings) is a palindrome. Return _an array of all the **palindrome pairs** of_ `...
null
Array,Hash Table,String,Trie
Hard
5,214,2237
1,689
hello coders welcome back to my channel let's solve lead code medium problem 1689 partitioning into minimum number of decimal binary numbers our decimal number is called dc binary number if each of its digits is either 0 or 1 without any leading zeros given a string n that represents positive decimal number return the ...
Partitioning Into Minimum Number Of Deci-Binary Numbers
detect-pattern-of-length-m-repeated-k-or-more-times
A decimal number is called **deci-binary** if each of its digits is either `0` or `1` without any leading zeros. For example, `101` and `1100` are **deci-binary**, while `112` and `3001` are not. Given a string `n` that represents a positive decimal integer, return _the **minimum** number of positive **deci-binary** n...
Use a three-layer loop to check all possible patterns by iterating through all possible starting positions, all indexes less than m, and if the character at the index is repeated k times.
Array,Enumeration
Easy
1764
318
Ko a Hello friends in this section we appointed discuss in another light the problem maximum product of violence you will be given string are the first step into votes which did not show any common latest multiple between the boobs 920 multiplication in all possible point to subscribe characters and Multiple Equations ...
Maximum Product of Word Lengths
maximum-product-of-word-lengths
Given a string array `words`, return _the maximum value of_ `length(word[i]) * length(word[j])` _where the two words do not share common letters_. If no such two words exist, return `0`. **Example 1:** **Input:** words = \[ "abcw ", "baz ", "foo ", "bar ", "xtfn ", "abcdef "\] **Output:** 16 **Explanation:** The two ...
null
Array,String,Bit Manipulation
Medium
null
1,846
hey everybody this is larry just me going over q3 of the buy wiggly contest 51 maximum element of after decreasing and rearranging so hit the like button hit the subscribe button join me on discord let me know what you think about this problem you know now or during the contest so yeah so the thing that i noticed about...
Maximum Element After Decreasing and Rearranging
maximum-element-after-decreasing-and-rearranging
You are given an array of positive integers `arr`. Perform some operations (possibly none) on `arr` so that it satisfies these conditions: * The value of the **first** element in `arr` must be `1`. * The absolute difference between any 2 adjacent elements must be **less than or equal to** `1`. In other words, `abs...
null
null
Medium
null
1,003
um hello so today we are going to do this problem check if words is valid um after parenthesis after substitution so um what this problem says is we get a string um and we want to determine if it's valid and what do we mean by valid here um it means that we start out with another empty string T and we want to transform...
Check If Word Is Valid After Substitutions
minimum-area-rectangle-ii
Given a string `s`, determine if it is **valid**. A string `s` is **valid** if, starting with an empty string `t = " "`, you can **transform** `t` **into** `s` after performing the following operation **any number of times**: * Insert string `"abc "` into any position in `t`. More formally, `t` becomes `tleft + "ab...
null
Array,Math,Geometry
Medium
null
1,198
all right so let's talk about the final smallest common element in all the rules so you're given environmentary so for every single row it's actually sorted in increasing order it doesn't matter and then return the smallest common element in all the rules so let's just look at a copper so if every single element is sor...
Find Smallest Common Element in All Rows
unpopular-books
Given an `m x n` matrix `mat` where every row is sorted in **strictly** **increasing** order, return _the **smallest common element** in all rows_. If there is no common element, return `-1`. **Example 1:** **Input:** mat = \[\[1,2,3,4,5\],\[2,4,5,8,10\],\[3,5,7,9,11\],\[1,3,5,7,9\]\] **Output:** 5 **Example 2:** ...
null
Database
Medium
null
1,642
To my channel Quote Surrey with Mike So today we are going to do question number 28 of our Grady playlist. We are going to do video number 28. Okay and today's question is going to be very interesting because you are going to learn a new thing. Lead code number 1642 It is not at all medium, it will be quite easy for yo...
Furthest Building You Can Reach
water-bottles
You are given an integer array `heights` representing the heights of buildings, some `bricks`, and some `ladders`. You start your journey from building `0` and move to the next building by possibly using bricks or ladders. While moving from building `i` to building `i+1` (**0-indexed**), * If the current building'...
Simulate the process until there are not enough empty bottles for even one full bottle of water.
Math,Simulation
Easy
null
114
hi guys welcome to my channel and today let's talk about lead code problem 114 so here is the problem and as you can see you are given a binary tree and you want to turn this into a linked list so for this kind of problem my recommendation is that you start with a very simple binary tree like a binary tree that has thr...
Flatten Binary Tree to Linked List
flatten-binary-tree-to-linked-list
Given the `root` of a binary tree, flatten the tree into a "linked list ": * The "linked list " should use the same `TreeNode` class where the `right` child pointer points to the next node in the list and the `left` child pointer is always `null`. * The "linked list " should be in the same order as a [**pre-order*...
If you notice carefully in the flattened tree, each node's right child points to the next node of a pre-order traversal.
Linked List,Stack,Tree,Depth-First Search,Binary Tree
Medium
766,1796
1,047
hey guys welcome to a new video in today's video we're going to look at a lead code problem and the problem's name is remove all adjacent duplicates in a string in this question we given a string s which consists of lowercase English letters in this question a duplicate removal consists of two equal and adjacent letter...
Remove All Adjacent Duplicates In String
maximize-sum-of-array-after-k-negations
You are given a string `s` consisting of lowercase English letters. A **duplicate removal** consists of choosing two **adjacent** and **equal** letters and removing them. We repeatedly make **duplicate removals** on `s` until we no longer can. Return _the final string after all such duplicate removals have been made_...
null
Array,Greedy,Sorting
Easy
2204
1,186
it boosted like an 808 my product Cartesian this is maximum subarray some with one deletion given integer given an integer of integers given an array of integers return the maximum sum for a non-empty subarray with at most for a non-empty subarray with at most for a non-empty subarray with at most one element deletion ...
Maximum Subarray Sum with One Deletion
building-h2o
Given an array of integers, return the maximum sum for a **non-empty** subarray (contiguous elements) with at most one element deletion. In other words, you want to choose a subarray and optionally delete one element from it so that there is still at least one element left and the sum of the remaining elements is maxim...
null
Concurrency
Medium
null
763
hey what's up guys let me just make all right hey what's up guys Nick white here I do Tekken coding stuff on twitch and YouTube check description for all my information I do the Premium Lee code solutions on my patreon if you want to reach out to me join the discord trying it back to everyone this is a partition proble...
Partition Labels
special-binary-string
You are given a string `s`. We want to partition the string into as many parts as possible so that each letter appears in at most one part. Note that the partition is done so that after concatenating all the parts in order, the resultant string should be `s`. Return _a list of integers representing the size of these ...
Draw a line from (x, y) to (x+1, y+1) if we see a "1", else to (x+1, y-1). A special substring is just a line that starts and ends at the same y-coordinate, and that is the lowest y-coordinate reached. Call a mountain a special substring with no special prefixes - ie. only at the beginning and end is the lowest y-coo...
String,Recursion
Hard
678
1,281
hi everybody this is Steve here and I do leave code problems to go through data structures and algorithms to help people prepare for coding interviews to ace through all of the cony and system design questions today we're going through a legal problem 1281 subtract the product and sum of digits of an integer before we ...
Subtract the Product and Sum of Digits of an Integer
can-make-palindrome-from-substring
Given an integer number `n`, return the difference between the product of its digits and the sum of its digits. **Example 1:** **Input:** n = 234 **Output:** 15 **Explanation:** Product of digits = 2 \* 3 \* 4 = 24 Sum of digits = 2 + 3 + 4 = 9 Result = 24 - 9 = 15 **Example 2:** **Input:** n = 4421 **Output:**...
Since we can rearrange the substring, all we care about is the frequency of each character in that substring. How to find the character frequencies efficiently ? As a preprocess, calculate the accumulate frequency of all characters for all prefixes of the string. How to check if a substring can be changed to a palindro...
Hash Table,String,Bit Manipulation,Prefix Sum
Medium
2165
796
hi welcome to everyone my name is kundan Kumar today we are going to see one important question on lead code related to a string see first of all we will try to understand what is question so copied so we have given two a string C s and gold we have given two string and we need to check goal is that means this string i...
Rotate String
reaching-points
Given two strings `s` and `goal`, return `true` _if and only if_ `s` _can become_ `goal` _after some number of **shifts** on_ `s`. A **shift** on `s` consists of moving the leftmost character of `s` to the rightmost position. * For example, if `s = "abcde "`, then it will be `"bcdea "` after one shift. **Example 1...
null
Math
Hard
null
373
hey what's up guys on solving 373 find the k pairs with small list numbers okay so the idea is that you're given a raise uh number two and a sorted uh sending order and adjk and if i pair uv which consists one element from first array and one uh element from second array that will return k pairs okay end up with the sm...
Find K Pairs with Smallest Sums
find-k-pairs-with-smallest-sums
You are given two integer arrays `nums1` and `nums2` sorted in **ascending order** and an integer `k`. Define a pair `(u, v)` which consists of one element from the first array and one element from the second array. Return _the_ `k` _pairs_ `(u1, v1), (u2, v2), ..., (uk, vk)` _with the smallest sums_. **Example 1:**...
null
Array,Heap (Priority Queue)
Medium
378,719,2150
1,496
so the first one is pathfinding so this one given that n is only up to ten to the fourth which is ten thousand you can actually put everything in the hash table right for and because every movement is in an integer point you just have to keep track of it so if you don't know if you move X plus one if you go sub you 2x ...
Path Crossing
lucky-numbers-in-a-matrix
Given a string `path`, where `path[i] = 'N'`, `'S'`, `'E'` or `'W'`, each representing moving one unit north, south, east, or west, respectively. You start at the origin `(0, 0)` on a 2D plane and walk on the path specified by `path`. Return `true` _if the path crosses itself at any point, that is, if at any time you ...
Find out and save the minimum of each row and maximum of each column in two lists. Then scan through the whole matrix to identify the elements that satisfy the criteria.
Array,Matrix
Easy
null
230
hey what's up youtube it's bobby g your number one and favorite leaked influencer today we are doing a problem called kate's smallest element in a binary search tree if you're working on graph reversals it's a good problem to start with um before i get into the video feel free to drop us up if i get a thousand subs by ...
Kth Smallest Element in a BST
kth-smallest-element-in-a-bst
Given the `root` of a binary search tree, and an integer `k`, return _the_ `kth` _smallest value (**1-indexed**) of all the values of the nodes in the tree_. **Example 1:** **Input:** root = \[3,1,4,null,2\], k = 1 **Output:** 1 **Example 2:** **Input:** root = \[5,3,6,2,4,null,null,1\], k = 3 **Output:** 3 **Cons...
Try to utilize the property of a BST. Try in-order traversal. (Credits to @chan13) What if you could modify the BST node's structure? The optimal runtime complexity is O(height of BST).
Tree,Depth-First Search,Binary Search Tree,Binary Tree
Medium
94,671
1,029
hey everybody this is Larry this is the third day of the June decoy daily challenge let's get right to it hit the like button hit the subscribe button let me know what you think two cities scheduling there are two and people and company is planning generally the cost of flying i've person to city a is cause of i-20 and...
Two City Scheduling
vertical-order-traversal-of-a-binary-tree
A company is planning to interview `2n` people. Given the array `costs` where `costs[i] = [aCosti, bCosti]`, the cost of flying the `ith` person to city `a` is `aCosti`, and the cost of flying the `ith` person to city `b` is `bCosti`. Return _the minimum cost to fly every person to a city_ such that exactly `n` people...
null
Hash Table,Tree,Depth-First Search,Breadth-First Search,Binary Tree
Hard
null
232
welcome back today we have this problem it's called deployment IQ using stacks implemented the first in first out queue using only two stacks they implement the queue should support the functionality it should be like push Peak pop and empty and when push pushed the element the pope removes Peak return the element at t...
Implement Queue using Stacks
implement-queue-using-stacks
Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (`push`, `peek`, `pop`, and `empty`). Implement the `MyQueue` class: * `void push(int x)` Pushes element x to the back of the queue. * `int pop()` Removes the element from th...
null
Stack,Design,Queue
Easy
225
1,713
hey everybody this is larry this is me going over a q4 of the reason by uh the leeco weekly contest minimum operations to make a subsequence so this one i think there are a couple of ways to think about it uh i've i think the two main solutions that i've seen um and variations within those two things um so i'm gonna go...
Minimum Operations to Make a Subsequence
dot-product-of-two-sparse-vectors
You are given an array `target` that consists of **distinct** integers and another integer array `arr` that **can** have duplicates. In one operation, you can insert any integer at any position in `arr`. For example, if `arr = [1,4,1,2]`, you can add `3` in the middle and make it `[1,4,3,1,2]`. Note that you can inser...
Because the vector is sparse, use a data structure that stores the index and value where the element is nonzero.
Array,Hash Table,Two Pointers,Design
Medium
null
1,877
hello everybody so in this video we will be looking at the lead code problem one eight seven minimize maximum pair sum in array so the problem statement says that the pair sum pair a b is equal to a plus b so that is uh if we have a pair of a and b and so their sum will be a plus b that is pretty common and the maximum...
Minimize Maximum Pair Sum in Array
find-followers-count
The **pair sum** of a pair `(a,b)` is equal to `a + b`. The **maximum pair sum** is the largest **pair sum** in a list of pairs. * For example, if we have pairs `(1,5)`, `(2,3)`, and `(4,4)`, the **maximum pair sum** would be `max(1+5, 2+3, 4+4) = max(6, 5, 8) = 8`. Given an array `nums` of **even** length `n`, pai...
null
Database
Easy
null
111
foreign hey everybody this is Larry this is day 10 for the week of daily challenge uh yeah hit the like button subscribe button join me on Discord let me know what you think about today's forum and yeah I've been uh I have a that huge backlog of drone videos I'm going to show you this one uh you know take a few seconds...
Minimum Depth of Binary Tree
minimum-depth-of-binary-tree
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. **Note:** A leaf is a node with no children. **Example 1:** **Input:** root = \[3,9,20,null,null,15,7\] **Output:** 2 **Example 2:** **Input:** root = \[2...
null
Tree,Depth-First Search,Breadth-First Search,Binary Tree
Easy
102,104
1,535
hey everybody this is Larry this is day six of the Leal daily challenge hit the like button hit the Subscribe button join me on Discord let me know what you think about today's F and the explanation and all that stuff I'm here in Sakura Juma uh and island off cargo Juma uh 15 minute fery right away uh and yeah I'm here...
Find the Winner of an Array Game
build-array-where-you-can-find-the-maximum-exactly-k-comparisons
Given an integer array `arr` of **distinct** integers and an integer `k`. A game will be played between the first two elements of the array (i.e. `arr[0]` and `arr[1]`). In each round of the game, we compare `arr[0]` with `arr[1]`, the larger integer wins and remains at position `0`, and the smaller integer moves to t...
Use dynamic programming approach. Build dp table where dp[a][b][c] is the number of ways you can start building the array starting from index a where the search_cost = c and the maximum used integer was b. Recursively, solve the small sub-problems first. Optimize your answer by stopping the search if you exceeded k cha...
Dynamic Programming
Hard
null
442
hello everyone welcome to quartus camp we are sixth day of october lead code challenge and the problem we are going to cover in this video is find all duplicates in an array so the input given here is an integer array nums which said to be having duplicate numbers that is each integer appear once or twice and we have t...
Find All Duplicates in an Array
find-all-duplicates-in-an-array
Given an integer array `nums` of length `n` where all the integers of `nums` are in the range `[1, n]` and each integer appears **once** or **twice**, return _an array of all the integers that appears **twice**_. You must write an algorithm that runs in `O(n)` time and uses only constant extra space. **Example 1:** ...
null
Array,Hash Table
Medium
448
1,758
hey everyone today we are solving lead code problem number 1758 minimum changes to make alternating binary string in this problem we are given a string s which is consisting only characters 0o and one and in one operation you can change any 0 to one or vice versa okay after that uh it is saying that string is called al...
Minimum Changes To Make Alternating Binary String
distribute-repeating-integers
You are given a string `s` consisting only of the characters `'0'` and `'1'`. In one operation, you can change any `'0'` to `'1'` or vice versa. The string is called alternating if no two adjacent characters are equal. For example, the string `"010 "` is alternating, while the string `"0100 "` is not. Return _the **m...
Count the frequencies of each number. For example, if nums = [4,4,5,5,5], frequencies = [2,3]. Each customer wants all of their numbers to be the same. This means that each customer will be assigned to one number. Use dynamic programming. Iterate through the numbers' frequencies, and choose some subset of customers to ...
Array,Dynamic Programming,Backtracking,Bit Manipulation,Bitmask
Hard
null
5
hey guys Oh welcome back to the channel Sarah I just want to start off by saying this is gonna be a very unusual media as compared to the previous ones and that's because I broke the mobile phone that I was using to write illustrations and so I'm gonna be doing it on a piece of paper until I fix that or I get a new dev...
Longest Palindromic Substring
longest-palindromic-substring
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end ...
String,Dynamic Programming
Medium
214,266,336,516,647
1,463
hey everyone welcome back today we are going to solve problem number 1463 Cherry pickup 2 first we will see the explanation of the problem statement in the logic on the code now let's dive into the solution so in this problem we are given a grid and two Bots right and the bot one will be at the top left corner and Bot ...
Cherry Pickup II
the-k-weakest-rows-in-a-matrix
You are given a `rows x cols` matrix `grid` representing a field of cherries where `grid[i][j]` represents the number of cherries that you can collect from the `(i, j)` cell. You have two robots that can collect cherries for you: * **Robot #1** is located at the **top-left corner** `(0, 0)`, and * **Robot #2** is...
Sort the matrix row indexes by the number of soldiers and then row indexes.
Array,Binary Search,Sorting,Heap (Priority Queue),Matrix
Easy
null
442
Hello volume is going to appear are very famous question find duplicates in the great so before solving the question we will see the problem once what we have to do in this then our personality problems are 432 with 89 and in this we have to point dry fruits like spa But if we see, here it has happened twice, so one to...
Find All Duplicates in an Array
find-all-duplicates-in-an-array
Given an integer array `nums` of length `n` where all the integers of `nums` are in the range `[1, n]` and each integer appears **once** or **twice**, return _an array of all the integers that appears **twice**_. You must write an algorithm that runs in `O(n)` time and uses only constant extra space. **Example 1:** ...
null
Array,Hash Table
Medium
448
24
welcome back to algojs today's question is Elite code 24 swap nodes in pairs so given a linked list swap every two adjacent nodes and return its head you must solve the problem without modifying the values in the list nodes only the nodes themselves may be changed so in example one we have converted this linked list so...
Swap Nodes in Pairs
swap-nodes-in-pairs
Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list's nodes (i.e., only nodes themselves may be changed.) **Example 1:** **Input:** head = \[1,2,3,4\] **Output:** \[2,1,4,3\] **Example 2:** **Input:** head = \[\] **Output:** \[\...
null
Linked List,Recursion
Medium
25,528
337
and today we're gonna working on it question number 337 house robert part three uh the thief has found himself a new place for his theory again okay and there is only one entrance to this area called route besides the route each house has one and only one apparent house after a tour the thief the smart thief realized t...
House Robber III
house-robber-iii
The thief has found himself a new place for his thievery again. There is only one entrance to this area, called `root`. Besides the `root`, each house has one and only one parent house. After a tour, the smart thief realized that all houses in this place form a binary tree. It will automatically contact the police if ...
null
Dynamic Programming,Tree,Depth-First Search,Binary Tree
Medium
198,213
380
hello everyone Aaron here and welcome back to lead code today we are doing the insert delete get random order one problem very catchy implement the randomized set class such that randomized set initializes the randomized set object makes sense insert the value returns a Boolean this inserts the item Val into the set if...
Insert Delete GetRandom O(1)
insert-delete-getrandom-o1
Implement the `RandomizedSet` class: * `RandomizedSet()` Initializes the `RandomizedSet` object. * `bool insert(int val)` Inserts an item `val` into the set if not present. Returns `true` if the item was not present, `false` otherwise. * `bool remove(int val)` Removes an item `val` from the set if present. Retur...
null
Array,Hash Table,Math,Design,Randomized
Medium
381
1,604
hello guys so here we are again to the second question of the cont of the week we contest 36 and let me thank you to the um user that told me about obs studio i am now using it so you don't need to see that movavi trial watermark so this question a word using same key card three or more times in a one hour period this ...
Alert Using Same Key-Card Three or More Times in a One Hour Period
least-number-of-unique-integers-after-k-removals
LeetCode company workers use key-cards to unlock office doors. Each time a worker uses their key-card, the security system saves the worker's name and the time when it was used. The system emits an **alert** if any worker uses the key-card **three or more times** in a one-hour period. You are given a list of strings `...
Use a map to count the frequencies of the numbers in the array. An optimal strategy is to remove the numbers with the smallest count first.
Array,Hash Table,Greedy,Sorting,Counting
Medium
null
130
hello everyone so let's talk about surround region so in this question i'm going to solve this question by union fine so unifying is actually a quick way to do that because um they are beneficial of doing this when you're trying to find a null that you should with um someone else before like they will take you out of o...
Surrounded Regions
surrounded-regions
Given an `m x n` matrix `board` containing `'X'` and `'O'`, _capture all regions that are 4-directionally surrounded by_ `'X'`. A region is **captured** by flipping all `'O'`s into `'X'`s in that surrounded region. **Example 1:** **Input:** board = \[\[ "X ", "X ", "X ", "X "\],\[ "X ", "O ", "O ", "X "\],\[ "X ", "...
null
Array,Depth-First Search,Breadth-First Search,Union Find,Matrix
Medium
200,286
127
hey everyone in this video we are going to solve the word ladder question on lead code so we are given a begin word and an adword and a list of words uh working as a dictionary and we need to return the number of words in the shortest transformation sequence to convert this begin word to the N word and the condition is...
Word Ladder
word-ladder
A **transformation sequence** from word `beginWord` to word `endWord` using a dictionary `wordList` is a sequence of words `beginWord -> s1 -> s2 -> ... -> sk` such that: * Every adjacent pair of words differs by a single letter. * Every `si` for `1 <= i <= k` is in `wordList`. Note that `beginWord` does not need ...
null
Hash Table,String,Breadth-First Search
Hard
126,433
236
hello and welcome back to the cracking thing youtube channel today we're going to be solving lead code problem 236 lowest common ancestor of a binary tree let's read the question given a binary tree find the lowest common ancestor lca of two nodes in the tree according to the definition of an lca on wikipedia the lowes...
Lowest Common Ancestor of a Binary Tree
lowest-common-ancestor-of-a-binary-tree
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the [definition of LCA on Wikipedia](https://en.wikipedia.org/wiki/Lowest_common_ancestor): "The lowest common ancestor is defined between two nodes `p` and `q` as the lowest node in `T` that has both `p` and `q` as...
null
Tree,Depth-First Search,Binary Tree
Medium
235,1190,1354,1780,1790,1816,2217
1,589
hey guys today we're going to solve lead call number 1589 maximum sum obtained of any permutation so we create an array of integers and an array of requests that is the range sum between a start and then end index and we need to return the maximum total sum of all requests among all permutations of nums and also the an...
Maximum Sum Obtained of Any Permutation
maximum-sum-obtained-of-any-permutation
We have an array of integers, `nums`, and an array of `requests` where `requests[i] = [starti, endi]`. The `ith` request asks for the sum of `nums[starti] + nums[starti + 1] + ... + nums[endi - 1] + nums[endi]`. Both `starti` and `endi` are _0-indexed_. Return _the maximum total sum of all requests **among all permuta...
null
null
Medium
null
1,970
hello guys so in this video what we will do we will basically discuss this problem from today's late course weekly contest so it's a actually a very good problem and a very basic concept of graph is required in this so first let's go through the problem statement so basically what's given is uh there is one based binar...
Last Day Where You Can Still Cross
sorting-the-sentence
There is a **1-based** binary matrix where `0` represents land and `1` represents water. You are given integers `row` and `col` representing the number of rows and columns in the matrix, respectively. Initially on day `0`, the **entire** matrix is **land**. However, each day a new cell becomes flooded with **water**. ...
Divide the string into the words as an array of strings Sort the words by removing the last character from each word and sorting according to it
String,Sorting
Easy
2168
917
We are going to do the question reverse only letters. See, we will be given a string which will have some letters and some special symbols or it may be some numbers too. The head of the story is that we have to reverse the spring but which We have special symbols like non-English characters, listen carefully, non-Engli...
Reverse Only Letters
boats-to-save-people
Given a string `s`, reverse the string according to the following rules: * All the characters that are not English letters remain in the same position. * All the English letters (lowercase or uppercase) should be reversed. Return `s` _after reversing it_. **Example 1:** **Input:** s = "ab-cd" **Output:** "dc-ba...
null
Array,Two Pointers,Greedy,Sorting
Medium
null
387
hey yo what's up my little coders let me show you in this tutorial how to solve the lethal question 387 first unique character in a string basically given the string we just need to return the index of the first unique character which we see in this string let's consider this example imagine that's the input string so ...
First Unique Character in a String
first-unique-character-in-a-string
Given a string `s`, _find the first non-repeating character in it and return its index_. If it does not exist, return `-1`. **Example 1:** **Input:** s = "leetcode" **Output:** 0 **Example 2:** **Input:** s = "loveleetcode" **Output:** 2 **Example 3:** **Input:** s = "aabb" **Output:** -1 **Constraints:** * `...
null
Hash Table,String,Queue,Counting
Easy
451
931
hey everyone today we are going to solve theal question minimum falling pass sum okay so let me explain with this example so description said when we move to next row we have three ways basically so directory below and uh diagonally left and right so my strategy is um to calculate the minimum number at each place and i...
Minimum Falling Path Sum
maximum-frequency-stack
Given an `n x n` array of integers `matrix`, return _the **minimum sum** of any **falling path** through_ `matrix`. A **falling path** starts at any element in the first row and chooses the element in the next row that is either directly below or diagonally left/right. Specifically, the next element from position `(ro...
null
Hash Table,Stack,Design,Ordered Set
Hard
null
27
hey are you doing so today we're gonna solve question number 27 remove elements we're gonna first read the question I'm gonna show you the thought process and how we solve it and then finally we're gonna code some of the solutions okay stay tuned all right let's read the question remove elements is the question we have...
Remove Element
remove-element
Given an integer array `nums` and an integer `val`, remove all occurrences of `val` in `nums` [**in-place**](https://en.wikipedia.org/wiki/In-place_algorithm). The order of the elements may be changed. Then return _the number of elements in_ `nums` _which are not equal to_ `val`. Consider the number of elements in `nu...
The problem statement clearly asks us to modify the array in-place and it also says that the element beyond the new length of the array can be anything. Given an element, we need to remove all the occurrences of it from the array. We don't technically need to remove that element per-say, right? We can move all the occu...
Array,Two Pointers
Easy
26,203,283
437
that's our time complexity for the two function approach o of n square now that we understood the time complexity of this approach now we can go and optimize it hi guys how are you all doing in this video we'll take a look at path sum three problem difficulty level is medium so let's see what the problem description is...
Path Sum III
path-sum-iii
Given the `root` of a binary tree and an integer `targetSum`, return _the number of paths where the sum of the values along the path equals_ `targetSum`. The path does not need to start or end at the root or a leaf, but it must go downwards (i.e., traveling only from parent nodes to child nodes). **Example 1:** **In...
null
Tree,Depth-First Search,Binary Tree
Medium
112,113,666,687
456
hello everyone welcome to our channel code with sunny and in this video we will be talking about the problem one three two pattern of fleet code its index is four five six okay so before moving on let's talk about the prerequisite that is being required when you solve this problem you must know the concept of binary se...
132 Pattern
132-pattern
Given an array of `n` integers `nums`, a **132 pattern** is a subsequence of three integers `nums[i]`, `nums[j]` and `nums[k]` such that `i < j < k` and `nums[i] < nums[k] < nums[j]`. Return `true` _if there is a **132 pattern** in_ `nums`_, otherwise, return_ `false`_._ **Example 1:** **Input:** nums = \[1,2,3,4\] ...
null
Array,Binary Search,Stack,Monotonic Stack,Ordered Set
Medium
null
606
hello everyone so in this video let us talk about one more problem from lead code it is an easy problem which is construct string from binary tree so you are given a root of a binary tree and you have to construct a string out of that which consists of parenthesis and integers of that binary tree with the pre-order tra...
Construct String from Binary Tree
construct-string-from-binary-tree
Given the `root` of a binary tree, construct a string consisting of parenthesis and integers from a binary tree with the preorder traversal way, and return it. Omit all the empty parenthesis pairs that do not affect the one-to-one mapping relationship between the string and the original binary tree. **Example 1:** *...
null
String,Tree,Depth-First Search,Binary Tree
Easy
536,652
1,624
hello welcome to today's daily lead code challenge let's get to today's question 1624 largest substring between two equal characters all right so this is an easy level problem let's get to the description given a string s return the length of the longest substring between two equal characters excluding the two characte...
Largest Substring Between Two Equal Characters
clone-binary-tree-with-random-pointer
Given a string `s`, return _the length of the longest substring between two equal characters, excluding the two characters._ If there is no such substring return `-1`. A **substring** is a contiguous sequence of characters within a string. **Example 1:** **Input:** s = "aa " **Output:** 0 **Explanation:** The optim...
Traverse the tree, keep a hashtable with you and create a nodecopy for each node in the tree. Start traversing the original tree again and connect the left, right and random pointers in the cloned tree the same way as the original tree with the help of the hashtable.
Hash Table,Tree,Depth-First Search,Breadth-First Search,Binary Tree
Medium
133,138,1634
1,762
hello everyone from today onwards I'm starting a series in which I'll be solving some lead code premium questions with different categories and different tags so as we know that there are not very much uh premium questions videos available on YouTube and internet so from now onwards I'll be solving only the lead code p...
Buildings With an Ocean View
furthest-building-you-can-reach
There are `n` buildings in a line. You are given an integer array `heights` of size `n` that represents the heights of the buildings in the line. The ocean is to the right of the buildings. A building has an ocean view if the building can see the ocean without obstructions. Formally, a building has an ocean view if al...
Assume the problem is to check whether you can reach the last building or not. You'll have to do a set of jumps, and choose for each one whether to do it using a ladder or bricks. It's always optimal to use ladders in the largest jumps. Iterate on the buildings, maintaining the largest r jumps and the sum of the remain...
Array,Greedy,Heap (Priority Queue)
Medium
null
725
hey so welcome back and we're going to do leak code problem 725 called split linked lists into parts and so we're going to do just that we're going to return a list of linked lists and we're going to split them up into K lists all right so I'm assuming you already read the problem so we'll go straight into implementati...
Split Linked List in Parts
split-linked-list-in-parts
Given the `head` of a singly linked list and an integer `k`, split the linked list into `k` consecutive linked list parts. The length of each part should be as equal as possible: no two parts should have a size differing by more than one. This may lead to some parts being null. The parts should be in the order of occ...
If there are N nodes in the list, and k parts, then every part has N/k elements, except the first N%k parts have an extra one.
Linked List
Medium
61,328
299
That a hello guys welcome to this new video but in this video we are talking about the next problem number one two three 021 and that means you must subscribe that How many are absolutely correct, meaning that out of the correct positions, there are only 13 numbers, there is only one number, the second account has only...
Bulls and Cows
bulls-and-cows
You are playing the **[Bulls and Cows](https://en.wikipedia.org/wiki/Bulls_and_Cows)** game with your friend. You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info: * The number of "bulls ", which are digits in the ...
null
Hash Table,String,Counting
Medium
null
931
hey everybody this is Larry this is day 19 of the Leo daily challenge hit the like button hit the Subscribe button press the one button uh join me on Discord let me know what you think about today's problem today's uh no just today's problem oh did the extra problem so we'll take a look at today is 931 minimum fling pa...
Minimum Falling Path Sum
maximum-frequency-stack
Given an `n x n` array of integers `matrix`, return _the **minimum sum** of any **falling path** through_ `matrix`. A **falling path** starts at any element in the first row and chooses the element in the next row that is either directly below or diagonally left/right. Specifically, the next element from position `(ro...
null
Hash Table,Stack,Design,Ordered Set
Hard
null
1,663
hey everyone nitish aside hope you're doing well so let's start with the question so the question is smallest string with a given numeric value okay so the numeric value of a lowercase character is defined as its position like one index in the alphabet so the numeric value of a is when b is 2 then c is 3 and z is 26 ok...
Smallest String With A Given Numeric Value
detect-cycles-in-2d-grid
The **numeric value** of a **lowercase character** is defined as its position `(1-indexed)` in the alphabet, so the numeric value of `a` is `1`, the numeric value of `b` is `2`, the numeric value of `c` is `3`, and so on. The **numeric value** of a **string** consisting of lowercase characters is defined as the sum of...
Keep track of the parent (previous position) to avoid considering an invalid path. Use DFS or BFS and keep track of visited cells to see if there is a cycle.
Array,Depth-First Search,Breadth-First Search,Union Find,Matrix
Medium
null
260
hello everybody welcome to my channel today is the day 23 and the problem is single number three so this is a problem theory of the single number series so if you haven't solved single number two already try to solve them before attempting this problem so that you will get some idea how to proceed so let's see the prob...
Single Number III
single-number-iii
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 runs in linear runtime complexity and uses only constant extra space. ...
null
Array,Bit Manipulation
Medium
136,137
983
hey everybody this is Larry this is March 27 28th well I mean it's my 27th year but the 28th day of the RICO daily challenge hit the like button hit the Subscribe button join me on Discord let me know what you think about today's Farm um so I came here so that I could click on the happy lead code button get 10 lead coi...
Minimum Cost For Tickets
validate-stack-sequences
You have planned some train traveling one year in advance. The days of the year in which you will travel are given as an integer array `days`. Each day is an integer from `1` to `365`. Train tickets are sold in **three different ways**: * a **1-day** pass is sold for `costs[0]` dollars, * a **7-day** pass is sold...
null
Array,Stack,Simulation
Medium
null
171
welcome back everyone we're going to be solving Lee code 171 Excel sheet column number so we're given a string called column title that represents the com title as it appears inside of an Excel sheet and we want to return the corresponding column number so the example they give us a to z is 1 to 26. double column A wou...
Excel Sheet Column Number
excel-sheet-column-number
Given a string `columnTitle` that represents the column title as appears in an Excel sheet, return _its corresponding column number_. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... **Example 1:** **Input:** columnTitle = "A " **Output:** 1 **Example 2:** **Input:** columnTitle = "AB " **Ou...
null
Math,String
Easy
168,2304
282
Hello Karishma Kapoor Welcome Surface Expression Ad Operator So let's get into this problem, today's problem is that you must have given an extension inside it, inside which only numbers will be stored and you must have given some target, now you have to tell yourself that your Which operators can you apply on your Pur...
Expression Add Operators
expression-add-operators
Given a string `num` that contains only digits and an integer `target`, return _**all possibilities** to insert the binary operators_ `'+'`_,_ `'-'`_, and/or_ `'*'` _between the digits of_ `num` _so that the resultant expression evaluates to the_ `target` _value_. Note that operands in the returned expressions **shoul...
Note that a number can contain multiple digits. Since the question asks us to find all of the valid expressions, we need a way to iterate over all of them. (Hint: Recursion!) We can keep track of the expression string and evaluate it at the very end. But that would take a lot of time. Can we keep track of the expressio...
Math,String,Backtracking
Hard
150,224,227,241,494
1,502
hey everybody this is Larry this is can make arithmetic progress from progression from sequence so this is Q one of the recent contest so you can watch myself this live after what's doing the contest so there won't be that much commentary but basically the idea I have is that okay we could make an arithmetic progressio...
Can Make Arithmetic Progression From Sequence
construct-k-palindrome-strings
A sequence of numbers is called an **arithmetic progression** if the difference between any two consecutive elements is the same. Given an array of numbers `arr`, return `true` _if the array can be rearranged to form an **arithmetic progression**. Otherwise, return_ `false`. **Example 1:** **Input:** arr = \[3,5,1\]...
If the s.length < k we cannot construct k strings from s and answer is false. If the number of characters that have odd counts is > k then the minimum number of palindrome strings we can construct is > k and answer is false. Otherwise you can construct exactly k palindrome strings and answer is true (why ?).
Hash Table,String,Greedy,Counting
Medium
null
857
hello guys welcome back to the channel today we are solving Elite code heart problem 857 minimum cost to hire key workers I would highly recommend you should read this problem statement at least twice because it is little bit tricky so I hope you have read the problem let's jump right into it what it is asking to make ...
Minimum Cost to Hire K Workers
positions-of-large-groups
There are `n` workers. You are given two integer arrays `quality` and `wage` where `quality[i]` is the quality of the `ith` worker and `wage[i]` is the minimum wage expectation for the `ith` worker. We want to hire exactly `k` workers to form a paid group. To hire a group of `k` workers, we must pay them according to ...
null
String
Easy
2260
690
everyone welcome to my channel so in this video i'm going to go over this question do some live coding work at the same time i'm going to try to follow the general interior steps while trying to solve this problem so first of all let's read through this question to get an understanding so you give a data structure of t...
Employee Importance
employee-importance
You have a data structure of employee information, including the employee's unique ID, importance value, and direct subordinates' IDs. You are given an array of employees `employees` where: * `employees[i].id` is the ID of the `ith` employee. * `employees[i].importance` is the importance value of the `ith` employ...
null
Hash Table,Depth-First Search,Breadth-First Search
Medium
339
191
groups so the problem is coming we are given a binary integer or integer in the form of binary format and we have to find the number of ones present in the binary integer so let's take an example one two three you know how to calculate the binary sleep so two follow zero then the problem is one that is four those four ...
Number of 1 Bits
number-of-1-bits
Write a function that takes the binary representation of an unsigned integer and returns the number of '1' bits it has (also known as the [Hamming weight](http://en.wikipedia.org/wiki/Hamming_weight)). **Note:** * Note that in some languages, such as Java, there is no unsigned integer type. In this case, the input ...
null
Bit Manipulation
Easy
190,231,338,401,461,693,767
9
in this video we'll be going over leak code question number nine palindrome number give it an integer we have to return true if the integer is a palindrome and return false if it's not now a palindrome is a sequence that reads the same backwards or forwards for example these numbers are palindromes because reading them...
Palindrome Number
palindrome-number
Given an integer `x`, return `true` _if_ `x` _is a_ _**palindrome**__, and_ `false` _otherwise_. **Example 1:** **Input:** x = 121 **Output:** true **Explanation:** 121 reads as 121 from left to right and from right to left. **Example 2:** **Input:** x = -121 **Output:** false **Explanation:** From left to right, i...
Beware of overflow when you reverse the integer.
Math
Easy
234,1375
318
hey everybody this is larry this is day 29 look at all those checks uh of the leeco may dairy challenge hit the like button hit the subscribe button join me on discord let me know what you think about today's prom maximum product of world links um yeah hope everyone's doing well the new contest or one of the new contes...
Maximum Product of Word Lengths
maximum-product-of-word-lengths
Given a string array `words`, return _the maximum value of_ `length(word[i]) * length(word[j])` _where the two words do not share common letters_. If no such two words exist, return `0`. **Example 1:** **Input:** words = \[ "abcw ", "baz ", "foo ", "bar ", "xtfn ", "abcdef "\] **Output:** 16 **Explanation:** The two ...
null
Array,String,Bit Manipulation
Medium
null
478
hi everyone this is sunny kumar from iit bhu and welcome to my channel code with sunny and today i am going to discuss the problem generate the random point in a circle index number is 478 and the problem is of medium type of lead code okay so let's discuss the problem now given the radius and xy positions of a center ...
Generate Random Point in a Circle
generate-random-point-in-a-circle
Given the radius and the position of the center of a circle, implement the function `randPoint` which generates a uniform random point inside the circle. Implement the `Solution` class: * `Solution(double radius, double x_center, double y_center)` initializes the object with the radius of the circle `radius` and th...
null
null
Medium
null
297
in this video we're going to look at a legal problem called serialize and deserialize binder tree so um the goal for this question is that we want to take this binary tree and we want to serialize this into a string so that we when we deserialize this we take the string that we serialize and then deserialize this and t...
Serialize and Deserialize Binary Tree
serialize-and-deserialize-binary-tree
Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment. Design an algorithm to serialize and deserialize a bi...
null
String,Tree,Depth-First Search,Breadth-First Search,Design,Binary Tree
Hard
271,449,652,765
1,019
hello everyone i'm here to do my 100 lego challenge today we have leeco 101.9 today we have leeco 101.9 today we have leeco 101.9 next greater note in linkedlist so this question is very long but i can summarize in this example now this example is input as a linked list like a node and two is connected to uh one is con...
Next Greater Node In Linked List
squares-of-a-sorted-array
You are given the `head` of a linked list with `n` nodes. For each node in the list, find the value of the **next greater node**. That is, for each node, find the value of the first node that is next to it and has a **strictly larger** value than it. Return an integer array `answer` where `answer[i]` is the value of ...
null
Array,Two Pointers,Sorting
Easy
88,360
785
hey everyone welcome back and let's write some more neat code today so today let's solve the problem is graph bipartite I don't know if I'm pronouncing that correctly but we're given an undirected graph with n nodes now n is not given as a parameter but we're also given a second parameter which is graph but thankfully ...
Is Graph Bipartite?
basic-calculator-iii
There is an **undirected** graph with `n` nodes, where each node is numbered between `0` and `n - 1`. You are given a 2D array `graph`, where `graph[u]` is an array of nodes that node `u` is adjacent to. More formally, for each `v` in `graph[u]`, there is an undirected edge between node `u` and node `v`. The graph has ...
null
Math,String,Stack,Recursion
Hard
224,227,781,1736
1,842
let's go slowly colon signer 800 542 next 7 digits now for this question to give us string now and it is uh um you must numeric string and uh this kind of number industry which is uh hiring so um to ask between the smallest Point you're larger than num that can be created by rearranging its digits so uh what do we do l...
Next Palindrome Using Same Digits
number-of-calls-between-two-persons
You are given a numeric string `num`, representing a very large **palindrome**. Return _the **smallest palindrome larger than**_ `num` _that can be created by rearranging its digits. If no such palindrome exists, return an empty string_ `" "`. A **palindrome** is a number that reads the same backward as forward. **E...
null
Database
Medium
null
140
hello everyone welcome back here is vanamsin and today we are diving into a challenging critical problem called World break 2 so let's get started first let's break down our problem so we are given a string as and a list of dictionary word and our task is to add spaces in the string to construct a sentence where each w...
Word Break II
word-break-ii
Given a string `s` and a dictionary of strings `wordDict`, add spaces in `s` to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in **any order**. **Note** that the same word in the dictionary may be reused multiple times in the segmentation. **Example 1:** **Input:...
null
Hash Table,String,Dynamic Programming,Backtracking,Trie,Memoization
Hard
139,472
11
hey guys welcome to the tech grant today we are going to solve the lead code problem of container with most water like and share the video subscribe to the channel to get further update so this problem says that we have to find container with most water and the container is defined using an array so given a non-negativ...
Container With Most Water
container-with-most-water
You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `ith` line are `(i, 0)` and `(i, height[i])`. Find two lines that together with the x-axis form a container, such that the container contains the most water. Return _the maximum amount of water...
The aim is to maximize the area formed between the vertical lines. The area of any container is calculated using the shorter line as length and the distance between the lines as the width of the rectangle. Area = length of shorter vertical line * distance between lines We can definitely get the maximum width ...
Array,Two Pointers,Greedy
Medium
42
645
um hello so today we are going to do this problem which is part of lead code October daily challenge the problem is set mismatch so we have a set of integers um which originally contained all numbers from 1 to n but there was an error and one of the numbers is duplicated and the other one is missing right um and so wha...
Set Mismatch
set-mismatch
You have a set of integers `s`, which originally contains all the numbers from `1` to `n`. Unfortunately, due to some error, one of the numbers in `s` got duplicated to another number in the set, which results in **repetition of one** number and **loss of another** number. You are given an integer array `nums` represe...
null
Array,Hash Table,Bit Manipulation,Sorting
Easy
287
239
hey guys how been going this is Jer let's solve a lead code problem today it's 239 sliding window maximum you're given an array of integers nums there's a sliding window of size K which is moving from the very left to the very right you can only see K numbers in the window yeah each time the sliding window moves right ...
Sliding Window Maximum
sliding-window-maximum
You are given an array of integers `nums`, there is a sliding window of size `k` which is moving from the very left of the array to the very right. You can only see the `k` numbers in the window. Each time the sliding window moves right by one position. Return _the max sliding window_. **Example 1:** **Input:** nums...
How about using a data structure such as deque (double-ended queue)? The queue size need not be the same as the window’s size. Remove redundant elements and the queue should store only elements that need to be considered.
Array,Queue,Sliding Window,Heap (Priority Queue),Monotonic Queue
Hard
76,155,159,265,1814
234
foreign question and the question's name is palindrome linked list so in this question we're given a head of a single linked list and we have to return true if it is a palindrome else we have to return false so palindrome is a sequence that reads the same forward and backward if you take a look at example one two one i...
Palindrome Linked List
palindrome-linked-list
Given the `head` of a singly linked list, return `true` _if it is a_ _palindrome_ _or_ `false` _otherwise_. **Example 1:** **Input:** head = \[1,2,2,1\] **Output:** true **Example 2:** **Input:** head = \[1,2\] **Output:** false **Constraints:** * The number of nodes in the list is in the range `[1, 105]`. * ...
null
Linked List,Two Pointers,Stack,Recursion
Easy
9,125,206,2236
1,694
hey everybody this is larry this is me going over q1 of the weekly contest 220 on the last lead code uh reformat phone number so this one actually to be honest um i had some trouble with during the contest just because i know that my weak point is just making sure about the edge cases and not getting wrong answers so u...
Reformat Phone Number
make-sum-divisible-by-p
You are given a phone number as a string `number`. `number` consists of digits, spaces `' '`, and/or dashes `'-'`. You would like to reformat the phone number in a certain manner. Firstly, **remove** all spaces and dashes. Then, **group** the digits from left to right into blocks of length 3 **until** there are 4 or f...
Use prefix sums to calculate the subarray sums. Suppose you know the remainder for the sum of the entire array. How does removing a subarray affect that remainder? What remainder does the subarray need to have in order to make the rest of the array sum up to be divisible by k? Use a map to keep track of the rightmost i...
Array,Hash Table,Prefix Sum
Medium
1016
73
so today we are looking at lead code number 73 it's a question called set matrix zeros okay so we have a m by n matrix and if an element is zero we want to set its entire row and inside entire column to zero and we want to do it in place so there are three different approaches to this you can see here in the follow-up ...
Set Matrix Zeroes
set-matrix-zeroes
Given an `m x n` integer matrix `matrix`, if an element is `0`, set its entire row and column to `0`'s. You must do it [in place](https://en.wikipedia.org/wiki/In-place_algorithm). **Example 1:** **Input:** matrix = \[\[1,1,1\],\[1,0,1\],\[1,1,1\]\] **Output:** \[\[1,0,1\],\[0,0,0\],\[1,0,1\]\] **Example 2:** **In...
If any cell of the matrix has a zero we can record its row and column number using additional memory. But if you don't want to use extra memory then you can manipulate the array instead. i.e. simulating exactly what the question says. Setting cell values to zero on the fly while iterating might lead to discrepancies. ...
Array,Hash Table,Matrix
Medium
289,2244,2259,2314
1,399
hey Aaron how's it going today we will be looking at this problem that is called count largest group and all the problem really asks you to do is that given an integer n each number from one to n is grouped according to the sum of its digits and you have to return how many groups have the largest size so all this probl...
Count Largest Group
page-recommendations
You are given an integer `n`. Each number from `1` to `n` is grouped according to the sum of its digits. Return _the number of groups that have the largest size_. **Example 1:** **Input:** n = 13 **Output:** 4 **Explanation:** There are 9 groups in total, they are grouped according sum of its digits of numbers from...
null
Database
Medium
2046,2097
349
Hello everyone welcome to my channel code story with mike so today we are going to do video number 27 of our lead code easy playlist, it is easy but it is a very good practice problem, we made it approachable and to a great extent from yesterday's question. Similar is lead code number 349 is easy marked by Microsoft an...
Intersection of Two Arrays
intersection-of-two-arrays
Given two integer arrays `nums1` and `nums2`, return _an array of their intersection_. Each element in the result must be **unique** and you may return the result in **any order**. **Example 1:** **Input:** nums1 = \[1,2,2,1\], nums2 = \[2,2\] **Output:** \[2\] **Example 2:** **Input:** nums1 = \[4,9,5\], nums2 = \...
null
Array,Hash Table,Two Pointers,Binary Search,Sorting
Easy
350,1149,1392,2190,2282
965
hello welcome to my channel i'm here to do my 100 lego challenge now today we have leeco 965 unit valued binary tree so a binary tree is unique value if every node in the tree has the same value return true if and only if the given tree is unit value now it's really uh intuitive looking at this chart there's only one v...
Univalued Binary Tree
unique-email-addresses
A binary tree is **uni-valued** if every node in the tree has the same value. Given the `root` of a binary tree, return `true` _if the given tree is **uni-valued**, or_ `false` _otherwise._ **Example 1:** **Input:** root = \[1,1,1,1,1,null,1\] **Output:** true **Example 2:** **Input:** root = \[2,2,2,5,2\] **Outpu...
null
Array,Hash Table,String
Easy
null
324
yo what's going on guys uh today we're gonna take a look at question number 324 wiggle sword 2. so let's uh first make sure that we understand the question we are given an Integrity nums and the question requires us to reorder it such that the zeroth index smaller than the first index and first and next is bigger than ...
Wiggle Sort II
wiggle-sort-ii
Given an integer array `nums`, reorder it such that `nums[0] < nums[1] > nums[2] < nums[3]...`. You may assume the input array always has a valid answer. **Example 1:** **Input:** nums = \[1,5,1,1,6,4\] **Output:** \[1,6,1,5,1,4\] **Explanation:** \[1,4,1,5,1,6\] is also accepted. **Example 2:** **Input:** nums = ...
null
Array,Divide and Conquer,Sorting,Quickselect
Medium
75,215,280,2085
279
in this video we're going to take a look at a legal problem called perfect squares so um basically we're given an integer n return the least number of perfect square numbers that sum to n so in this case you can see we have a so perfect square is an integer that is a square of an integer so in other words uh it is the ...
Perfect Squares
perfect-squares
Given an integer `n`, return _the least number of perfect square numbers that sum to_ `n`. A **perfect square** is an integer that is the square of an integer; in other words, it is the product of some integer with itself. For example, `1`, `4`, `9`, and `16` are perfect squares while `3` and `11` are not. **Example ...
null
Math,Dynamic Programming,Breadth-First Search
Medium
204,264
1,018
yeahyeah Hi Hi Hi everyone, I'm a programmer. Today I'll introduce to you a math problem with the following pronouns. The binary prefix can be divided by 5. What problem do we have? The details as follows give us an array of large integers a including only the numbers 0 and 1. We consider n at final position y with y a...
Binary Prefix Divisible By 5
largest-perimeter-triangle
You are given a binary array `nums` (**0-indexed**). We define `xi` as the number whose binary representation is the subarray `nums[0..i]` (from most-significant-bit to least-significant-bit). * For example, if `nums = [1,0,1]`, then `x0 = 1`, `x1 = 2`, and `x2 = 5`. Return _an array of booleans_ `answer` _where_ ...
null
Array,Math,Greedy,Sorting
Easy
830
1,637
hi guys subi I hope that you guys are doing good uh you'll see widest vertical area between two points containing no points so it has been as by Microsoft not pretty much but yeah we can see the problem itself it just says that we have n points on a 2d plane and where every point is just given two coordinates x i comma...
Widest Vertical Area Between Two Points Containing No Points
string-compression-ii
Given `n` `points` on a 2D plane where `points[i] = [xi, yi]`, Return _the **widest vertical area** between two points such that no points are inside the area._ A **vertical area** is an area of fixed-width extending infinitely along the y-axis (i.e., infinite height). The **widest vertical area** is the one with the ...
Use dynamic programming. The state of the DP can be the current index and the remaining characters to delete. Having a prefix sum for each character can help you determine for a certain character c in some specific range, how many characters you need to delete to merge all occurrences of c in that range.
String,Dynamic Programming
Hard
null
1,663
so lead code 1663 smallest string with a given numeric value so we defined the numeric value of a character as its position in the alphabet the numeric value of a string is just the sum of its character's numeric value and then you're given n and k two integers you need to return the lexicographically smallest string w...
Smallest String With A Given Numeric Value
detect-cycles-in-2d-grid
The **numeric value** of a **lowercase character** is defined as its position `(1-indexed)` in the alphabet, so the numeric value of `a` is `1`, the numeric value of `b` is `2`, the numeric value of `c` is `3`, and so on. The **numeric value** of a **string** consisting of lowercase characters is defined as the sum of...
Keep track of the parent (previous position) to avoid considering an invalid path. Use DFS or BFS and keep track of visited cells to see if there is a cycle.
Array,Depth-First Search,Breadth-First Search,Union Find,Matrix
Medium
null
976
solving liquid problem number 976 largest parameter triangle so um what does a triangle mean by definition in a triangle the sum of two sides must always be greater than the other side for any sides of the triangle so if we have a triangle of side A B and C then the sum of sides a plus b is always greater than C sum of...
Largest Perimeter Triangle
minimum-area-rectangle
Given an integer array `nums`, return _the largest perimeter of a triangle with a non-zero area, formed from three of these lengths_. If it is impossible to form any triangle of a non-zero area, return `0`. **Example 1:** **Input:** nums = \[2,1,2\] **Output:** 5 **Explanation:** You can form a triangle with three si...
null
Array,Hash Table,Math,Geometry,Sorting
Medium
null
328
Hello Various Welcome to the Second World Family Don't Turn On Paul Actress Time of Today's Question is Audible Inclination Meaning of All the Best Point in a Trader to Something on Point in a Trader to Something on Point in a Trader to Something on 10 Lines and Will Update It And Even It In It Movie World Recording Pa...
Odd Even Linked List
odd-even-linked-list
Given the `head` of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return _the reordered list_. The **first** node is considered **odd**, and the **second** node is **even**, and so on. Note that the relative order inside both the even and odd groups s...
null
Linked List
Medium
725
83
trust me nobody likes duplicates they cause so much redundancy and take up your so much disk space as well and they provide very little extra information correct so finding duplicates in any data structure becomes a very practical problem and that is why it is asked by so many tech companies so what can you do about it...
Remove Duplicates from Sorted List
remove-duplicates-from-sorted-list
Given the `head` of a sorted linked list, _delete all duplicates such that each element appears only once_. Return _the linked list **sorted** as well_. **Example 1:** **Input:** head = \[1,1,2\] **Output:** \[1,2\] **Example 2:** **Input:** head = \[1,1,2,3,3\] **Output:** \[1,2,3\] **Constraints:** * The numb...
null
Linked List
Easy
82,1982
74
hey guys let's solve Le code 74 which is search a 2d Matrix so you're given an M byn integer Matrix and they're calling that Matrix and that has two different properties one each row is sorted in non-decreasing order so that's a way of non-decreasing order so that's a way of non-decreasing order so that's a way of sayi...
Search a 2D Matrix
search-a-2d-matrix
You are given an `m x n` integer matrix `matrix` with the following two properties: * Each row is sorted in non-decreasing order. * The first integer of each row is greater than the last integer of the previous row. Given an integer `target`, return `true` _if_ `target` _is in_ `matrix` _or_ `false` _otherwise_. ...
null
Array,Binary Search,Matrix
Medium
240
152
hello everyone so today we will be doing lead code problem 142 that is maximum products are barry so we are given an integer array norms and we have to find a sub array that has got the largest product and we just have to return the product so here are few examples now let us try to understand the problem statement in ...
Maximum Product Subarray
maximum-product-subarray
Given an integer array `nums`, find a subarray that has the largest product, and return _the product_. The test cases are generated so that the answer will fit in a **32-bit** integer. **Example 1:** **Input:** nums = \[2,3,-2,4\] **Output:** 6 **Explanation:** \[2,3\] has the largest product 6. **Example 2:** **I...
null
Array,Dynamic Programming
Medium
53,198,238,628,713
1,710
hey guys how's it going in this video i'm going to walk through this leeco 1710 maximum unit on the truck and this question was asked by amazon for 42 times in the past six months so it was quite popular in amazon interviews and luckily this question is kind of easy let's walk through so you are assigned to put some am...
Maximum Units on a Truck
find-servers-that-handled-most-number-of-requests
You are assigned to put some amount of boxes onto **one truck**. You are given a 2D array `boxTypes`, where `boxTypes[i] = [numberOfBoxesi, numberOfUnitsPerBoxi]`: * `numberOfBoxesi` is the number of boxes of type `i`. * `numberOfUnitsPerBoxi` is the number of units in each box of the type `i`. You are also given...
To speed up the next available server search, keep track of the available servers in a sorted structure such as an ordered set. To determine if a server is available, keep track of the end times for each task in a heap and add the server to the available set once the soonest task ending time is less than or equal to th...
Array,Greedy,Heap (Priority Queue),Ordered Set
Hard
null
1,639
hmm hello guys so let's understand today question hi that uh see one two three four five six seven eight nine ten let's go hello guys so today we are going to understand you the question that we have is uh 1639 and this question has been asked in uh the topmost company like uh Microsoft Amazon and atlassian right so ma...
Number of Ways to Form a Target String Given a Dictionary
friendly-movies-streamed-last-month
You are given a list of strings of the **same length** `words` and a string `target`. Your task is to form `target` using the given `words` under the following rules: * `target` should be formed from left to right. * To form the `ith` character (**0-indexed**) of `target`, you can choose the `kth` character of th...
null
Database
Easy
null
3
hi my name is david today we're going to do number three longest substring without repeating characters we have a function here that takes an s and it wants us to return the length of the longest substring that doesn't repeat any characters so here we can see a substring is a b c and then there's a repeat so abc would ...
Longest Substring Without Repeating Characters
longest-substring-without-repeating-characters
Given a string `s`, find the length of the **longest** **substring** without repeating characters. **Example 1:** **Input:** s = "abcabcbb " **Output:** 3 **Explanation:** The answer is "abc ", with the length of 3. **Example 2:** **Input:** s = "bbbbb " **Output:** 1 **Explanation:** The answer is "b ", with t...
null
Hash Table,String,Sliding Window
Medium
159,340,1034,1813,2209
280
Wiggles sort given an uncertain terrain nums reorder it in place such that numbers of zero is going to be less than or equal to members of one will she'll be greater than or equal to members of two which will be less than or equal to members of three etc so we basically want to create this pattern in the input array so...
Wiggle Sort
wiggle-sort
Given an integer array `nums`, reorder it such that `nums[0] <= nums[1] >= nums[2] <= nums[3]...`. You may assume the input array always has a valid answer. **Example 1:** **Input:** nums = \[3,5,2,1,6,4\] **Output:** \[3,5,1,6,2,4\] **Explanation:** \[1,6,2,5,3,4\] is also accepted. **Example 2:** **Input:** nums...
null
Array,Greedy,Sorting
Medium
75,324,2085
139
hey guys it's off by one here and today we're going to be solving word break in this problem we're given a string s and a dictionary of strings called word dict and the problem wants us to return true if s can be split up into the dictionary words so for example here we have the string lead code and we have the word di...
Word Break
word-break
Given a string `s` and a dictionary of strings `wordDict`, return `true` if `s` can be segmented into a space-separated sequence of one or more dictionary words. **Note** that the same word in the dictionary may be reused multiple times in the segmentation. **Example 1:** **Input:** s = "leetcode ", wordDict = \[ "...
null
Hash Table,String,Dynamic Programming,Trie,Memoization
Medium
140
69
hello everyone so in this video we'll talk about the problem from lead code the problem name is square root function so you have to implement actually a square root function in which you are given a non-negative integer as an input given a non-negative integer as an input given a non-negative integer as an input and yo...
Sqrt(x)
sqrtx
Given a non-negative integer `x`, return _the square root of_ `x` _rounded down to the nearest integer_. The returned integer should be **non-negative** as well. You **must not use** any built-in exponent function or operator. * For example, do not use `pow(x, 0.5)` in c++ or `x ** 0.5` in python. **Example 1:** ...
Try exploring all integers. (Credits: @annujoshi) Use the sorted property of integers to reduced the search space. (Credits: @annujoshi)
Math,Binary Search
Easy
50,367
1,624
Hello everyone welcome back today we are going to talk about lead question number 1624 whose name is Largest sub string between two equal characters let's know what this problem is saying see this problem basically what is it that we have to give two characters Finding the string between two equal characters. Finding t...
Largest Substring Between Two Equal Characters
clone-binary-tree-with-random-pointer
Given a string `s`, return _the length of the longest substring between two equal characters, excluding the two characters._ If there is no such substring return `-1`. A **substring** is a contiguous sequence of characters within a string. **Example 1:** **Input:** s = "aa " **Output:** 0 **Explanation:** The optim...
Traverse the tree, keep a hashtable with you and create a nodecopy for each node in the tree. Start traversing the original tree again and connect the left, right and random pointers in the cloned tree the same way as the original tree with the help of the hashtable.
Hash Table,Tree,Depth-First Search,Breadth-First Search,Binary Tree
Medium
133,138,1634
4
for median of two sort of the ways there are two sorted arrays number one thumbs to of size M in and respectively finding me I'm too - so anyways overall one time me I'm too - so anyways overall one time me I'm too - so anyways overall one time compacting should be or log M plus n they'd have one in time you may assume...
Median of Two Sorted Arrays
median-of-two-sorted-arrays
Given two sorted arrays `nums1` and `nums2` of size `m` and `n` respectively, return **the median** of the two sorted arrays. The overall run time complexity should be `O(log (m+n))`. **Example 1:** **Input:** nums1 = \[1,3\], nums2 = \[2\] **Output:** 2.00000 **Explanation:** merged array = \[1,2,3\] and median is ...
null
Array,Binary Search,Divide and Conquer
Hard
null
408
hello today we're going to be doing lead code problem number 408 which is valid word abbreviation so this problem States a string can be abbreviated by replacing any number of non-adjacent non-empty any number of non-adjacent non-empty any number of non-adjacent non-empty substrings with their lengths the links should ...
Valid Word Abbreviation
valid-word-abbreviation
A string can be **abbreviated** by replacing any number of **non-adjacent**, **non-empty** substrings with their lengths. The lengths **should not** have leading zeros. For example, a string such as `"substitution "` could be abbreviated as (but not limited to): * `"s10n "` ( `"s ubstitutio n "`) * `"sub4u4 "` ( ...
null
Two Pointers,String
Easy
411,527,2184
991
hey everyone hope you're doing well so let's start with the question so the question is broken calculator okay so there is a broken calculator that has an integer start value on its display initially in one operation you can basically multiply the number on the display by 2 or you can perform an operation of subtract 1...
Broken Calculator
array-of-doubled-pairs
There is a broken calculator that has the integer `startValue` on its display initially. In one operation, you can: * multiply the number on display by `2`, or * subtract `1` from the number on display. Given two integers `startValue` and `target`, return _the minimum number of operations needed to display_ `targ...
null
Array,Hash Table,Greedy,Sorting
Medium
2117
269
hello and welcome back to the cracking Fang YouTube channel it has been many months since I've made a lead code video but more people are watching the channel now so I figured I would just make some more videos and what better way to start then with my favorite problem of all time lead code 269 alien dictionary let's r...
Alien Dictionary
alien-dictionary
There is a new alien language that uses the English alphabet. However, the order among the letters is unknown to you. You are given a list of strings `words` from the alien language's dictionary, where the strings in `words` are **sorted lexicographically** by the rules of this new language. Return _a string of the u...
null
Array,String,Depth-First Search,Breadth-First Search,Graph,Topological Sort
Hard
210
1,595
hey everybody this is larry this is me going with q4 of the leeco daily weekly contest 207 uh minimum cost to connect to a group of points so this is a very tricky problem let's see uh how many people solved it as of right now about 114 um yeah so i think the first thing to notice is that n is less than is equal to 12 ...
Minimum Cost to Connect Two Groups of Points
minimum-cost-to-connect-two-groups-of-points
You are given two groups of points where the first group has `size1` points, the second group has `size2` points, and `size1 >= size2`. The `cost` of the connection between any two points are given in an `size1 x size2` matrix where `cost[i][j]` is the cost of connecting point `i` of the first group and point `j` of t...
null
null
Hard
null
211
hey so welcome back and this is another daily code problem so today's March 19th and it was another try question actually so let's take a peek at it so yesterday was also a try question but it was actually about creating the data structure itself it wasn't really much of a an algorithm or a liquid problem behind it was...
Design Add and Search Words Data Structure
design-add-and-search-words-data-structure
Design a data structure that supports adding new words and finding if a string matches any previously added string. Implement the `WordDictionary` class: * `WordDictionary()` Initializes the object. * `void addWord(word)` Adds `word` to the data structure, it can be matched later. * `bool search(word)` Returns ...
You should be familiar with how a Trie works. If not, please work on this problem: Implement Trie (Prefix Tree) first.
String,Depth-First Search,Design,Trie
Medium
208,746
482
hey guys welcome to the hub today we're going to talk about our third LICO algorithm problem the code number 482 license key formatting so it's a very basic problem but it's very popular recently it got frequently asked by some companies so as always I'm gonna provide not only the solution but more importantly what are...
License Key Formatting
license-key-formatting
You are given a license key represented as a string `s` that consists of only alphanumeric characters and dashes. The string is separated into `n + 1` groups by `n` dashes. You are also given an integer `k`. We want to reformat the string `s` such that each group contains exactly `k` characters, except for the first g...
null
String
Easy
null