ALL-IN-ONE Algorithms

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Find the minimum depth of a binary tree. The minimum depth is the number of nodes along the shortest path from the root node to the nearest leaf node.,

, Tree BFS Pattern,

"Given the head of a Singly LinkedList and a number 'k', rotate the LinkedList to the right by 'k' nodes. Input put: - Head -> (1) -> (2) -> (3) -> (4) -> (5) -> (6) -> null - k=3 Output : Head -> (4) -> (5) -> (6) -> (1) -> (2) -> (3) -> null ",

,In-Place Reversal Of LinkedList Pattern,

"Given the head of a Singly LinkedList, reverse the LinkedList. Write a function to return the new head of the reversed LinkedList. Input put: Head -> (2) -> (4) -> (6) -> null Output : Head -> (6) -> (4) -> (2) -> null ",

,In-Place Reversal Of LinkedList Pattern,

"Given a list of intervals, merge all the overlapping intervals to produce a list that has only mutually exclusive intervals. Example 1: Intervals: [[1,4], [2,5], [7,9]] Output: [[1,5], [7,9]] Explanation: Since the first two intervals [1,4] and [2,5] overlap, we merged them into one [1,5].",

,Merge Intervals Pattern,

Explain the type of Binary Search Templates,

there are 3 types

"Given a binary tree, populate an array to represent its level-by-level traversal. You should populate the values of all nodes of each level from left to right in separate sub-arrays.",

,Tree BFS Pattern,

Find the path with the maximum sum in a given binary tree. Write a function that returns the maximum sum. A path can be defined as a sequence of nodes between any two leaf nodes and doesn't necessarily pass through the root.,

, Tree DFS Pattern,

"Suppose you are given an array containing non-negative numbers representing heights of a set of buildings. Now, because of differences in heights of buildings water can be trapped between them. Find the two buildings that will trap the most amount of water. Write a function that will return the maximum volume of water that will be trapped between these two buildings. Example 1: Input: [1, 3, 5, 4, 1] Output: 6 Explanation: The maximum water will be trapped between buildings of height 3 and 4.",

, Two Pointers Pattern,

" Find the peak from a Bitonic Array A peak element is an element that is greater than its neighbours. Given an input array nums, where nums[i] ≠ nums[i+1], find a peak element and return its index. The array may contain multiple peaks, in that case, return the index to any one of the peaks is fine. You may imagine that nums[-1] = nums[n] = -∞. Example 1: Input: nums = [1,2,3,1] Output: 2 Explanation: 3 is a peak element and your function should return the index number 2. Example 2: Input: nums = [1,2,1,3,5,6,4] Output: 1 or 5 Explanation: Your function can return either index number 1 where the peak element is 2, or index number 5 where the peak element is 6. Note: Your solution should be in logarithmic complexity.",

,Binary Search Pattern ,

"**This question probably won't come up in an interview, it is a bit too long to write. But it consists of two smaller problems Find the target from a Bitonic Array Given a bitonic sequence of n distinct elements, write a program to find a given target in the bitonic sequence in O(log n) time. A Bitonic Sequence is a sequence of numbers which is first strictly increasing then after a point decreasing. ( only one peak) Examples: Input : arr[] = {-3, 7, 8, 20, 17, 5, 1}; taget = 20 Output : Found at index 3 Input : arr[] = {5, 6, 7, 8, 9, 10, 1, 2, 3}; target = 30 Output : Not Found ",

,Binary Search Pattern ,

"Find Rotation cout in an asc order array with no duplicates Given an array of numbers which is sorted in ascending order and is rotated 'k' times around a pivot, find 'k'. You can assume that the array does not have any duplicates. Example 1: Input: [10, 15, 1, 3, 8] Output: 2 Explanation: The array has been rotated 2 times.",

,Binary Search Pattern ,

"Find Square root of X Implement 'int sqrt(int x)' Compute and return the square root of x, where x is guaranteed to be a non-negative integer. Since the return type is an integer, the decimal digits are truncated and only the integer part of the result is returned. Example 1: Input: 4 Output: 2 Example 2: Input: 8 Output: 2 Explanation: The square root of 8 is 2.82842..., and since the decimal part is truncated, 2 is returned.",

,Binary Search Pattern ,

"Find minimum difference in an asc sorted array with no duplicates Given an array of numbers sorted in ascending order, find the element in the array that has the minimum difference with the given target. Example 1: Input: [4, 6, 10], target = 7 Output: 6 Example 2: Input: [4, 6, 10], target = 4 Output: 4 Example 3: Input: [1, 3, 8, 10, 15], target = 12 Output: 10 Example 4: Input: [4, 6, 10], target = 17 Output: 10",

,Binary Search Pattern ,

"Find the ceiling target Or exact target from an asc order array without duplicates Given an array of numbers sorted in ascending order, find the ceiling of a given 'target' number. The ceiling of the 'target' will be the smallest element in the given array greater than or equal to the 'target'. Write a function to return the index of the ceiling of the 'target'. If there isn't any ceiling return -1. Example 1: Input: [4, 6, 10], t = 6 Output: 1 Explanation: The smallest number >= 6 is 6 at index 1. Example 2: Input: [1, 3, 8, 10, 15], t = 12 Output: 4 Explanation: The smallest number >= 12 is 15 at 4. Example 3: Input: [4, 6, 10], t = 17 Output: -1 Explanation: There is no such number >= 17 in the given array. Example 4: Input: [4, 6, 10], t = -1 Output: 0 Explanation: The smallest number >= -1 is 4 at index 0.",

,Binary Search Pattern ,

"Find the flooring target Or exact target from an asc order array without duplicates Given an array of numbers sorted in ascending order, find the flooring of a given 'target' number. The flooring of the 'target' will be the largest element in the given array that is smaller than or equal to the 'target'. Write a function to return the index of the flooring of the 'target'. If there isn't any flooring then return -1. Example 1: Input: [4, 6, 10], t = 6 Output: 1 Explanation: The largest number <= 6 is 6 at index 1. Example 2: Input: [1, 3, 8, 10, 15], t = 12 Output: 3 Explanation: The largest number <= 12 is 10 at index 3. Example 3: Input: [4, 6, 10], t = 3 Output: -1 Explanation: There is no such number <= 3 in the given array. Example 4: Input: [4, 6, 10], t = 11 Output: 2 Explanation: The largest number <= 11 is 10 at index 2. ",

,Binary Search Pattern ,

"Find the index of the target in a rotated asc array with no duplicates Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]). You are given a target value to search. If found in the array return its index, otherwise return -1. Example 1: Input: nums = [4,5,6,7,0,1,2], target = 0 Output: 4 Example 2: Input: nums = [4,5,6,7,0,1,2], target = 3 Output: -1",

,Binary Search Pattern ,

"Find the most left index in an asc sorted array with duplicates Given an array of numbers sorted in ascending order, find the first appealing index of the 'target' number. • If there is no such target, then return -1. • Assume there will be duplicates Example 1: Input: [1, 3, 5], t = 1 Output: 0 Example 2: Input: [1, 1, 3, 3, 5, 5], t = 5 Output: 4 Example 3: Input: [1, 1, 3, 3, 5, 5], t = 4 Output: -1",

,Binary Search Pattern ,

"Find the most right index in an asc sorted array with duplicates Given an array of numbers sorted in ascending order, find the last appealing index of the 'target' number. • If there is no such target, then return -1. • Assume there will be duplicates Example 1: Input: [1, 3, 5], t = 1 Output: 0 Example 2: Input: [1, 1, 3, 3, 5, 5], t = 5 Output: 5 Example 3: Input: [1, 1, 3, 3, 5, 5], t = 4 Output: -1",

,Binary Search Pattern ,

"Find the next letter from an asc sorted circulated array Given an array of lowercase letters sorted in ascending order, find the next letter in the given array, greater than a given 'target'. • Assume the given array is an imagine circular array, which means that the last letter is assumed to be connected with the first letter. • This also means that if given the last letter in the array and the next letter is the first letter in the array. Write a function to return the next letter of the given 'target'. Example 1: Input: ['a', 'c', 'f', 'h'], target = 'f' Output: 'h' Explanation: The next letter of 'f' is 'h' in the given array. Example 2: Input: ['a', 'c', 'f', 'h'], target = 'b' Output: 'c' Explanation: The next letter of 'b' is 'c' in the given array Example 3: Input: ['a', 'c', 'f', 'h'], target = 'm' Output: 'a' Explanation: As the array is assumed to be circulated from the end. Example 4: Input: ['a', 'c', 'f', 'h'], target = 'h' Output: 'a' Explanation: As the array is assumed to be circulated from the end.",

,Binary Search Pattern ,

"Find the target from an order-agnostic sorted array. Given a sorted array of numbers, find if a given target number is present in the array. • Although the input array is sorted whether it is in ascending or descending order is unknown. • The array can have duplicates. Write a function to return the target index if it is present in the array, otherwise return -1. Example 1: Input: [4, 6, 10], t = 10 Output: 2 Example 2: Input: [1, 2, 3, 4, 5, 6, 7], t = 5 Output: 4 Example 3: Input: [10, 6, 4], t = 10 Output: 0 Example 4: Input: [10, 6, 4], t = 4 Output: 2",

,Binary Search Pattern ,

"Find the target from an unknown size asc sorted array Given an integer array sorted in ascending order, write a function to search the target num in the given array. • If target exists, then return its index, otherwise, return -1. • However, the array size is unknown to you. You may only access the array using an ArrayReader interface, where ArrayReader.get(k) returns the element of the array at index k (0-indexed). • You may assume all integers in the array are less than 10000, and if you access the array out of bounds, ArrayReader.get() will return Integer.MAX_VALUE (2147483647). Example 1: Input: array = [-1,0,3,5,9,12], target = 9 Output: 4 Explanation: 9 exists in nums and its index is 4 Example 2: Input: array = [-1,0,3,5,9,12], target = 2 Output: -1 Explanation: 2 does not exist in nums so return -1",

,Binary Search Pattern ,

"Given an array of integers that sorted in ascending order, find the starting and ending position of a given target value. Example 1: Input: nums = [5,7,7,8,8,10], target = 8 Output: [3,4] Example 2: Input: nums = [5,7,7,8,8,10], target = 6 Output: [-1,-1]",

,Binary Search Pattern ,

"Given an unsorted array containing numbers and a number 'k', find the first 'k' missing positive numbers in the array. Example 1: Input: [3, -1, 4, 5, 5], k=3 Output: [1, 2, 6] Explanation: The smallest missing positive numbers are 1, 2 and 6. Example 2: Input: [2, 3, 4], k=3 Output: [1, 5, 6] Explanation: The smallest missing positive numbers are 1, 5 and 6. Example 3: Input: [-2, -3, 4], k=2 Output: [1, 2] Explanation: The smallest missing positive numbers are 1 and 2.",

,Cyclic Sort Pattern,

"Given an unsorted array containing numbers, find the smallest missing positive number in it. Example 1: Input: [-3, 1, 5, 4, 2] Output: 3 Explanation: The smallest missing positive number is '3' Example 2: Input: [3, -2, 0, 1, 2] Output: 4 Example 3: Input: [3, 2, 5, 1] Output: 4",

,Cyclic Sort Pattern,

"We are given an array containing 'n' distinct numbers taken from the range 0 to 'n'. Since the array has only 'n' numbers out of the total 'n+1' numbers, find the missing number. Example 1: Input: [4, 0, 3, 1] Output: 2 Example 2: Input: [8, 3, 5, 2, 4, 6, 0, 1] Output: 7",

,Cyclic Sort Pattern,

"We are given an array containing 'n' objects. Each object, when created, was assigned a unique number from 1 to 'n' based on their creation sequence. This means that the object with sequence number '3' was created just before the object with sequence number '4'. Write a function to sort the objects in-place on their creation sequence number in O(n)O(n) and without any extra space. For simplicity, let's assume we are passed an integer array containing only the sequence numbers, though each number is an object. We are given an array containing 'n' objects. Each object, when created, was assigned a unique number from 1 to 'n' based on their creation sequence. This means that the object with sequence number '3' was created just before the object with sequence number '4'. Write a function to sort the objects in-place on their creation sequence number in O(n)O(n) and without any extra space. For simplicity, let's assume we are passed an integer array containing only the sequence numbers, though each number is an object. Example 1: Input: [3, 1, 5, 4, 2] Output: [1, 2, 3, 4, 5] Example 2: Input: [2, 6, 4, 3, 1, 5] Output: [1, 2, 3, 4, 5, 6] Example 3: Input: [1, 5, 6, 4, 3, 2] Output: [1, 2, 3, 4, 5, 6]",

,Cyclic Sort Pattern,

"We are given an unsorted array containing 'n' numbers taken from the range 1 to 'n'. The array has some duplicates, find all the duplicate numbers without using any extra space. Example 1: Input: [3, 4, 4, 5, 5] Output: [4, 5] Example 2: Input: [5, 4, 7, 2, 3, 5, 3] Output: [3, 5]",

,Cyclic Sort Pattern,

"We are given an unsorted array containing 'n' numbers taken from the range 1 to 'n'. The array originally contained all the numbers from 1 to 'n', but due to a data error, one of the numbers got duplicated which also resulted in one number going missing. Find both these numbers. Example 1: Input: [3, 1, 2, 5, 2] Output: [2, 4] Explanation: '2' is duplicated and '4' is missing. Example 2: Input: [3, 1, 2, 3, 6, 4] Output: [3, 5] Explanation: '3' is duplicated and '5' is missing.",

,Cyclic Sort Pattern,

"We are given an unsorted array containing 'n+1' numbers taken from the range 1 to 'n'. The array has only one duplicate but it can be repeated multiple times. Find that duplicate number without using any extra space. You are, however, allowed to modify the input array. Example 1: Input: [1, 4, 4, 3, 2] Output: 4 Example 2: Input: [2, 1, 3, 3, 5, 4] Output: 3 Example 3: Input: [2, 4, 1, 4, 4] Output: 4",

,Cyclic Sort Pattern,

"We are given an unsorted array containing numbers taken from the range 1 to 'n'. The array can have duplicates, which means some numbers will be missing. Find all those missing numbers. Example 1: Input: [2, 3, 1, 8, 2, 3, 5, 1] Output: 4, 6, 7 Explanation: The array should have all numbers from 1 to 8, due to duplicates 4, 6, and 7 are missing. Example 2: Input: [2, 4, 1, 2] Output: 3 Example 3: Input: [2, 3, 2, 1] Output: 4",

,Cyclic Sort Pattern,

"Any number will be called a happy number if, after repeatedly replacing it with a number equal to the sum of the square of all of its digits, leads us to number '1'. All other (not-happy) numbers will never reach '1'. Instead, they will be stuck in a cycle of numbers which does not include '1'. Example 1: Input: 23 Output: true (23 is a happy number) Explanations: Here are the steps to find out that 23 is a happy number: 2^2 + 3 ^22 ​2 ​​ +3 ​2 ​​ = 4 + 9 = 13 1^2 + 3^21 ​2 ​​ +3 ​2 ​​ = 1 + 9 = 10 1^2 + 0^21 ​2 ​​ +0 ​2 ​​ = 1 + 0 = 1",

,Fast & Slow Pointers Pattern,

"Given the head of a Singly LinkedList that contains a cycle, write a function to find the starting node of the cycle.",

,Fast & Slow Pointers Pattern,

"Given the head of a Singly LinkedList, write a function to determine if the LinkedList has a cycle in it or not.",

,Fast & Slow Pointers Pattern,

"Given the head of a Singly LinkedList, write a method to check if the LinkedList is a palindrome or not. Your algorithm should use constant space and the input LinkedList should be in the original form once the algorithm is finished. The algorithm should have O(N)O(N) time complexity where 'N' is the number of nodes in the LinkedList. Example 1: Input: 2 -> 4 -> 6 -> 4 -> 2 -> null Output: true Example 2: Input: 2 -> 4 -> 6 -> 4 -> 2 -> 2 -> null Output: false",

,Fast & Slow Pointers Pattern,

"Given the head of a Singly LinkedList, write a method to modify the LinkedList such that the nodes from the second half of the LinkedList are inserted alternately to the nodes from the first half in reverse order. So if the LinkedList has nodes 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> null, your method should return 1 -> 6 -> 2 -> 5 -> 3 -> 4 -> null. Your algorithm should not use any extra space and the input LinkedList should be modified in-place. Example 1: Input: 2 -> 4 -> 6 -> 8 -> 10 -> 12 -> null Output: 2 -> 12 -> 4 -> 10 -> 6 -> 8 -> null Example 2: Input: 2 -> 4 -> 6 -> 8 -> 10 -> null Output: 2 -> 10 -> 4 -> 8 -> 6 -> null",

,Fast & Slow Pointers Pattern,

"Given the head of a Singly LinkedList, write a method to return the middle node of the LinkedList. If the total number of nodes in the LinkedList is even, return the second middle node. Example 1: Input: 1 -> 2 -> 3 -> 4 -> 5 -> null Output: 3 Example 2: Input: 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> null Output: 4 Example 3: Input: 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> null Output: 4",

,Fast & Slow Pointers Pattern,

"Given the head of a LinkedList and a number 'k', reverse every 'k' sized sub-list starting from the head. If, in the end, you are left with a sub-list with less than 'k' elements, reverse it too.",

,In-Place Reversal Of LinkedList Pattern,

"Given the head of a LinkedList and a number 'k', reverse every alternating 'k' sized sub-list starting from the head. If, in the end, you are left with a sub-list with less than 'k' elements, reverse it too.",

,In-Place Reversal Of LinkedList Pattern,

"Given the head of a LinkedList and two positions 'p' and 'q', reverse the LinkedList from position 'p' to 'q'.",

,In-Place Reversal Of LinkedList Pattern,

"Given a list of intervals representing the start and end time of 'N' meetings, find the minimum number of rooms required to hold all the meetings. Example 1: Meetings: [[1,4], [2,5], [7,9]] Output: 2 Explanation: Since [1,4] and [2,5] overlap, we need two rooms to hold these two meetings. [7,9] can occur in any of the two rooms later. Example 2: Meetings: [[6,7], [2,4], [8,12]] Output: 1 Explanation: None of the meetings overlap, therefore we only need one room to hold all meetings. Example 3: Meetings: [[1,4], [2,3], [3,6]] Output:2 Explanation: Since [1,4] overlaps with the other two meetings [2,3] and [3,6], we need two rooms to hold all the meetings. Example 4: Meetings: [[4,5], [2,3], [2,4], [3,5]] Output: 2 Explanation: We will need one room for [2,3] and [3,5], and another room for [2,4] and [4,5]. Here is a visual representation of Example 4:",

,Merge Intervals Pattern,

"Given a list of non-overlapping intervals sorted by their start time, insert a given interval at the correct position and merge all necessary intervals to produce a list that has only mutually exclusive intervals. Example 1: Input: Intervals=[[1,3], [5,7], [8,12]], New Interval=[4,6] Output: [[1,3], [4,7], [8,12]] Explanation: After insertion, since [4,6] overlaps with [5,7], we merged them into one [4,7]. Example 2: Input: Intervals=[[1,3], [5,7], [8,12]], New Interval=[4,10] Output: [[1,3], [4,12]] Explanation: After insertion, since [4,10] overlaps with [5,7] & [8,12], we merged them into [4,12]. Example 3: Input: Intervals=[[2,3],[5,7]], New Interval=[1,4] Output: [[1,4], [5,7]] Explanation: After insertion, since [1,4] overlaps with [2,3], we merged them into one [1,4]. ",

,Merge Intervals Pattern,

"Given an array of intervals representing 'N' appointments, find out if a person can attend all the appointments. Example 1: Appointments: [[1,4], [2,5], [7,9]] Output: false Explanation: Since [1,4] and [2,5] overlap, a person cannot attend both of these appointments. Example 2: Appointments: [[6,7], [2,4], [8,12]] Output: true Explanation: None of the appointments overlaps, therefore a person can attend all of them. Example 3: Appointments: [[4,5], [2,3], [3,6]] Output: false Explanation: Since [4,5] and [3,6] overlap, a person cannot attend both of these appointments. ",

,Merge Intervals Pattern,

"Given two lists of intervals, find the intersection of these two lists. Each list consists of disjoint intervals sorted on their start time. Example 1: Input: arr1=[[1, 3], [5, 6], [7, 9]], arr2=[[2, 3], [5, 7]] Output: [2, 3], [5, 6], [7, 7] Explanation: The output list contains the common intervals between the two lists. Example 2: Input: arr1=[[1, 3], [5, 7], [9, 12]], arr2=[[5, 10]] Output: [5, 7], [9, 10] Explanation: The output list contains the common intervals between the two lists.",

,Merge Intervals Pattern,

"We are given a list of Jobs. Each job has a Start time, an End time, and a CPU load when it is running. Our goal is to find the maximum CPU load at any time if all the jobs are running on the same machine. Example 1: Jobs: [[1,4,3], [2,5,4], [7,9,6]] Output: 7 Explanation: Since [1,4,3] and [2,5,4] overlap, their maximum CPU load (3+4=7) will be when both the jobs are running at the same time i.e., during the time interval (2,4). Example 2: Jobs: [[6,7,10], [2,4,11], [8,12,15]] Output: 15 Explanation: None of the jobs overlaps, therefore we will take the maximum load of any job which is 15. Example 3: Jobs: [[1,4,2], [2,4,1], [3,6,5]] Output: 8 Explanation: Maximum CPU load will be 8 as all jobs overlap during the time interval [3,4]. ",

,Merge Intervals Pattern,

"We are given an array containing positive and negative numbers. Suppose the array contains a number 'M' at a particular index. Now, if 'M' is positive we will move forward 'M' indices and if 'M' is negative move backwards 'M' indices. You should assume that the array is circular which means two things: If, while moving forward, we reach the end of the array, we will jump to the first element to continue the movement. If, while moving backwards, we reach the beginning of the array, we will jump to the last element to continue the movement. Write a method to determine if the array has a cycle. The cycle should have more than one element and should follow one direction which means the cycle should not contain both forward and backward movements. Example 1: Input: [1, 2, -1, 2, 2] Output: true Explanation: The array has a cycle among indices: 0 -> 1 -> 3 -> 0 Example 2: Input: [2, 2, -1, 2] Output: true Explanation: The array has a cycle among indices: 1 -> 3 -> 1 Example 3: Input: [2, 1, -1, -2] Output: false Explanation: The array does not have any cycle.",

,Merge Intervals Pattern,

"Given a string and a list of words, find all the starting indices of substrings in the given string that are a concatenation of all the given words exactly once without any overlapping of words. It is given that all words are of the same length. Example 1: Input: String=""catfoxcat"", Words=[""cat"", ""fox""] Output: [0, 3] Explanation: The two substring containing both the words are ""catfox"" & ""foxcat"". Example 2: Input: String=""catcatfoxfox"", Words=[""cat"", ""fox""] Output: [3] Explanation: The only substring containing both the words is ""catfox"".",

,Sliding Windows Pattern,

"Given a string and a pattern, find all anagrams of the pattern in the given string. An anagram is a Permutation of a string. For example, "abc" has the following six anagrams: abc acb bac bca cab cba Write a function to return a list of starting indices of the anagrams of the pattern in the given string. Example 1: Input: String=""ppqp"", Pattern=""pq"" Output: [1, 2] Explanation: The two anagrams of the pattern in the given string are ""pq"" and ""qp"". Example 2: Input: String=""abbcabc"", Pattern=""abc"" Output: [2, 3, 4] Explanation: The three anagrams of the pattern in the given string are ""bca"", ""cab"", and ""abc"".",

,Sliding Windows Pattern,

"Given a string and a pattern, find out if the string contains any permutation of the pattern. A permutation is defined as the re-arranging of the characters of the string. For example, "abc" has the following six permutations: abc acb bac bca cab cba If a string has 'n' distinct characters it will have n!n! permutations. Example 1: Input: String=""oidbcaf"", Pattern=""abc"" Output: true Explanation: The string contains ""bca"" which is a permutation of the given pattern. Example 2: Input: String=""odicf"", Pattern=""dc"" Output: false Explanation: No permutation of the pattern is present in the given string as a substring. Example 3: Input: String=""bcdxabcdy"", Pattern=""bcdyabcdx"" Output: true Explanation: Both the string and the pattern are a permutation of each other.",

,Sliding Windows Pattern,

"Given a binary tree, populate an array to represent its level-by-level traversal in reverse order, i.e., the lowest level comes first. You should populate the values of all nodes in each level from left to right in separate sub-arrays.",

,Tree BFS Pattern,

"Given a string and a pattern, find the smallest substring in the given string which has all the characters of the given pattern. Example 1: Input: String=""aabdec"", Pattern=""abc"" Output: ""abdec"" Explanation: The smallest substring having all characters of the pattern is ""abdec"" Example 2: Input: String=""abdabca"", Pattern=""abc"" Output: ""abc"" Explanation: The smallest substring having all characters of the pattern is ""abc"". Example 3: Input: String=""adcad"", Pattern=""abc"" Output: """" Explanation: No substring in the given string has all characters of the pattern.",

,Sliding Windows Pattern,

"Given a string with lowercase letters only, if you are allowed to replace no more than 'k' letters with any letter, find the length of the longest substring having the same letters after replacement. Example 1: Input: String=""aabccbb"", k=2 Output: 5 Explanation: Replace the two 'c' with 'b' to have a longest repeating substring ""bbbbb"". Example 2: Input: String=""abbcb"", k=1 Output: 4 Explanation: Replace the 'c' with 'b' to have a longest repeating substring ""bbbb"". Example 3: Input: String=""abccde"", k=1 Output: 3 Explanation: Replace the 'b' or 'd' with 'c' to have the longest repeating substring ""ccc"".",

,Sliding Windows Pattern,

"Given a string, find the length of the longest substring in it with no more than K distinct characters. Example 1: Input: String=""araaci"", K=2 Output: 4 Explanation: The longest substring with no more than '2' distinct characters is ""araa"". Example 2: Input: String=""araaci"", K=1 Output: 2 Explanation: The longest substring with no more than '1' distinct characters is ""aa"". Example 3: Input: String=""cbbebi"", K=3 Output: 5 Explanation: The longest substrings with no more than '3' distinct characters are ""cbbeb"" & ""bbebi"".",

,Sliding Windows Pattern,

"Given a string, find the length of the longest substring which has no repeating characters. Example 1: Input: String=""aabccbb"" Output: 3 Explanation: The longest substring without any repeating characters is ""abc"". Example 2: Input: String=""abbbb"" Output: 2 Explanation: The longest substring without any repeating characters is ""ab"". Example 3: Input: String=""abccde"" Output: 3 Explanation: Longest substrings without any repeating characters are ""abc"" & ""cde"".",

,Sliding Windows Pattern,

"Given an array containing 0s and 1s, if you are allowed to replace no more than 'k' 0s with 1s, find the length of the longest contiguous subarray having all 1s. Example 1: Input: Array=[0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1], k=2 Output: 6 Explanation: Replace the '0' at index 5 and 8 to have the longest contiguous subarray of 1s having length 6. Example 2: Input: Array=[0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1], k=3 Output: 9 Explanation: Replace the '0' at index 6, 9, and 10 to have the longest contiguous subarray of 1s having length 9.",

,Sliding Windows Pattern,

"Given an array of characters where each character represents a fruit tree, you are given two baskets and your goal is to put the maximum number of fruits in each basket. The only restriction is that each basket can have only one type of fruit. You can start with any tree, but once you have started you can't skip a tree. You will pick one fruit from each tree until you cannot, i.e., you will stop when you have to pick from a third fruit type. Write a function to return the maximum number of fruits in both the baskets. Example 1: Input: Fruit=['A', 'B', 'C', 'A', 'C'] Output: 3 Explanation: We can put 2 'C' in one basket and one 'A' in the other from the subarray ['C', 'A', 'C'] Example 2: Input: Fruit=['A', 'B', 'C', 'B', 'B', 'C'] Output: 5 Explanation: We can put 3 'B' in one basket and two 'C' in the other basket. This can be done if we start with the second letter: ['B', 'C', 'B', 'B', 'C']",

,Sliding Windows Pattern,

"Given an array of positive numbers and a positive number 'S', find the length of the smallest contiguous subarray whose sum is greater than or equal to 'S'. Return 0, if no such subarray exists. Example 1: Input: [2, 1, 5, 2, 3, 2], S=7 Output: 2 Explanation: The smallest subarray with a sum great than or equal to '7' is [5, 2]. Example 2: Input: [2, 1, 5, 2, 8], S=7 Output: 1 Explanation: The smallest subarray with a sum greater than or equal to '7' is [8]. Example 3: Input: [3, 4, 1, 1, 6], S=8 Output: 3 Explanation: Smallest subarrays with a sum greater than or equal to '8' are [3, 4, 1] or [1, 1, 6].",

,Sliding Windows Pattern,

"Given an array of positive numbers and a positive number 'k', find the maximum sum of any contiguous subarray of size 'k'. Example 1: Input: [2, 1, 5, 1, 3, 2], k=3 Output: 9 Explanation: Subarray with maximum sum is [5, 1, 3]. Example 2: Input: [2, 3, 4, 1, 5], k=2 Output: 7 Explanation: Subarray with maximum sum is [3, 4].",

,Sliding Windows Pattern,

"Find K closest points to the origin You are given a list of points on the plane and find K closest points to the origin (0, 0). • Here, the distance between two points on a plane is the Euclidean distance • You may return the answer in any order. • The answer is guaranteed to be unique Example 1: Input: points = [[1,3],[-2,2]], K = 1 Output: [[-2,2]] Explanation: The distance between (1, 3) and the origin is sqrt(10). The distance between (-2, 2) and the origin is sqrt(8). Since sqrt(8) < sqrt(10), (-2, 2) is closer to the origin. We only want the closest K = 1 points from the origin, so the answer is just [[-2,2]]. Example 2: Input: points = [[3,3],[5,-1],[-2,4]], K = 2 Output: [[3,3],[-2,4]]",

,Top N Elements Pattern,

"Find the Kth smallest element in unsorted array with duplicates Given an unsorted array of numbers, find Kth smallest number in it. Please note that it is the Kth smallest number in the sorted order, not the Kth distinct element. Example 1: Input: [1, 5, 12, 2, 11, 5], K = 3 Output: 5 Explanation: As the first 2 smallest numbers are [1, 2] Example 2: Input: [1, 5, 12, 2, 11, 5], K = 4 Output: 5 (2nd 5 as that is duplicates) Explanation: As the first 3 smallest numbers are [1, 2, 5] Example 3: Input: [5, 12, 11, -1, 12], K = 3 Output: 11 Explanation: As the first 2 smallest numbers are [-1, 5] ",

,Top N Elements Pattern,

"Given a non-empty array of integers, return the k most frequent elements. Example 1: Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] Example 2: Input: nums = [1], k = 1 Output: [1]",

,Top N Elements Pattern,

"Given an unsorted array of numbers, find Kth LARGEST numbers Example 1: Input: [3, 1, 5, 12, 2, 11], K = 3 Output: [5, 12, 11] Example 2: Input: [5, 12, 11, -1, 12], K = 3 Output: [12, 11, 12]",

,Top N Elements Pattern,

"Given an unsorted array of numbers, find the smallest K elements. Example 1: Input: [3, 1, 5, 12, 2, 11], K = 3 Output: [1, 2, 3] Example 2: Input: [5, 12, 11, -1, 12], K = 3 Output: [-1, 5, 11]",

,Top N Elements Pattern,

"Kth Largest Element in a Stream Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element. Your class will have a constructor which accepts an integer k and an integer array nums, which contains initial elements from the stream. For each call to the method add(), return the element representing the kth largest element in the stream. Example: int k = 3; int[] arr = [4,5,8,2]; KthLargest kthLargest = new KthLargest(3, arr); kthLargest.add(3); // returns 4 kthLargest.add(5); // returns 5 kthLargest.add(10); // returns 5 kthLargest.add(9); // returns 8 kthLargest.add(4); // returns 8",

,Top N Elements Pattern,

"Maximum Frequency Stack Implement FreqStack, a class which simulates the operation of a stack-like data structure. FreqStack has two functions: • push(int x), which pushes an integer x onto the stack. • pop(), which removes and returns the most frequent element in the stack. ◦ If there is a tie for the most frequent element, the element closest to the top of the stack is removed and returned. Example 1: instructions 1. Push(5) 2. Push(7) 3. Push(5) 4. Push(7) 5. Push(4) 6. Push(5) 7. Pop() -> 5 8. Pop() -> 7 9. Pop() -> 5 10. Pop() -> 4 Explanation: After making six .push operations, the stack is [5,7,5,7,4,5] from bottom to top. Then: pop() -> returns 5, as 5 is the most frequent. The stack becomes [5,7,5,7,4]. pop() -> returns 7, as 5 and 7 is the most frequent, but 7 is closest to the top. The stack becomes [5,7,5,4]. pop() -> returns 5. The stack becomes [5,7,4]. pop() -> returns 4. The stack becomes [5,7].",

,Top N Elements Pattern,

"Maximum distinct elements after removing k elements Given an array arr[] containing n elements. The problem is to find the maximum number of distinct elements (non-repeating) after removing k elements from the array. Note: 1 <= k <= n. Examples: Input : arr[] = {5, 7, 5, 5, 1, 2, 2}, k = 3 Output : 4 Remove 2 occurrences of element 5 and 1 occurrence of element 2. Input : arr[] = {1, 2, 3, 4, 5, 6, 7}, k = 5 Output : 2 Input : arr[] = {1, 2, 2, 2}, k = 1 Output : 1",

,Top N Elements Pattern,

"Minimum Cost to Connect Sticks You have some sticks with positive integer lengths. You can connect any two sticks of lengths X and Y into one stick by paying a cost of X + Y. You perform this action until there is one stick remaining. Return the minimum cost of connecting all the given sticks into one stick in this way. Example 1: Input: sticks = [2,4,3] Output: 14 Explanation: 2+3=5, 4+5=9, thus 5+9=14 Example 2: Input: sticks = [1,8,3,5] Output: 30 Explanation: 1+3=4, 4+5=9, 8+9=17 thus 4+9+17=30 ",

,Top N Elements Pattern,

"Rearrange String k Distance Apart Given a non-empty string s and an integer k, rearrange the string such that the same characters are at least distance k from each other. • All input strings are given in lowercase letters. • If it is not possible to rearrange the string, return an empty string """". Example 1: Input: s = ""aabbcc"", k = 3 Output: ""abcabc"" Explanation: The same letters are at least distance 3 from each other. Example 2: Input: s = ""aaabc"", k = 3 Output: """" Explanation: It is not possible to rearrange the string. Example 3: Input: s = ""aaadbbcc"", k = 2 Output: ""abacabcd"" Explanation: The same letters are at least distance 2 from each other. ",

,Top N Elements Pattern,

"Reorganize String Given a string S, check if the letters can be rearranged so that two characters that are adjacent to each other are not the same. If possible, output any possible result. If not possible, return the empty string. Example 1: Input: S = ""aab"" Output: ""aba"" Example 2: Input: S = ""aaab"" Output: """" Note: • S will consist of lowercase letters and have a length in range [1, 500]. ",

,Top N Elements Pattern,

"Sort Characters By Frequency Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input:""tree"" Output:""eert"" Explanation:'e' appears twice while 'r' and 't' both appear once. So 'e' must appear before both 'r' and 't'. Therefore ""eetr"" is also a valid answer. Example 2: Input:""cccaaa"" Output:""cccaaa"" Explanation: Both 'c' and 'a' appear three times, so ""aaaccc"" is also a valid answer. Note that ""cacaca"" is incorrect, as the same characters must be together. Example 3: Input:""Aabb"" Output:""bbAa"" Explanation: ""bbaA"" is also a valid answer, but ""Aabb"" is incorrect. Note that 'A' and 'a' are treated as two different characters. ",

,Top N Elements Pattern,

"Sum of all elements between k1'th and k2'th smallest elements (exclusively) • Given an array of integers and two numbers k1 and k2. • Find the sum of all elements between given two k1'th and k2'th smallest elements of the array. Example 1 : Input : arr = {20, 8, 22, 4, 12, 10, 14}, k1 = 3, k2 = 6 Output: 26 Explanation: 3rd smallest element is 10. 6th smallest element is 20. Sum of all element between k1 & k2 is 12 + 14 = 26 Example 2 : Input : arr[] = {10, 2, 50, 12, 48, 13}, k1 = 2, k2 = 6 Output : 73 ",

,Top N Elements Pattern,

"Task Scheduler Given a char array representing tasks CPU need to do. It contains capital letters A to Z where different letters represent different tasks. Tasks could be done without the original order. Each task could be done in one interval. For each interval, the CPU could finish one task or just be idle. However, there is a non-negative cooling interval n that means between two same tasks, there must be at least n intervals that CPUs are doing different tasks or just be idle. You need to return the least number of intervals the CPU will take to finish all the given tasks. Example: Input: tasks = ['A','A','A','B','B','B'], n = 2 Output: 8 Explanation: A -> B -> idle -> A -> B -> idle -> A -> B. Note: 1. The number of tasks is in the range [1, 10000]. 2. The integer n is in the range [0, 100].",

,Top N Elements Pattern,

Convert An Array To Min Heap,

,Top N Elements Pattern,

"Given a binary tree and a node, find the level order successor of the given node in the tree. The level order successor is the node that appears right after the given node in the level order traversal. Input: given node 3 the root node (1) e.g 1 / \ 2 3 / \ 4 5 output: (4)",

,Tree BFS Pattern,

"Given a binary tree, connect each node with its level order successor. The last node of each level should point to a null node. e.g 1-- >null / \ 2 ->3-->null / \ 4 ->5 --> null ",

,Tree BFS Pattern,

"Given a binary tree, connect each node with its level order successor. The last node of each level should point to the first node of the next level. e.g 1 / \ 2 3 / \ 4 5 so, addition to the existing connection, the output would added that 1 -> 2 -> 3 -> 4 -> 5",

,Tree BFS Pattern,

"Given a binary tree, populate an array to represent its zigzag level order traversal. You should populate the values of all nodes of the first level from left to right, then right to left for the next level and keep alternating in the same manner for the following levels.",

,Tree BFS Pattern,

"Given a binary tree, populate an array to represent the averages of all of its levels. e.g 1 / \ 2 3 output: [ 1, 2.5]",

,Tree BFS Pattern,

"Given a binary tree, return an array containing all the boundary nodes of the tree in an anti-clockwise direction. The boundary of a tree contains all nodes in the left view, all leaves, and all nodes in the right view. Please note that there should not be any duplicate nodes. For example, the root is only included in the left view; similarly, if a level has only one node we should include it in the left view.",

,Tree BFS Pattern,

"Given a binary tree, return an array containing nodes in its right view. The right view of a binary tree is the set of nodes visible when the tree is seen from the right side.",

,Tree BFS Pattern,

"Given a binary tree and a number 'S', find all paths from root-to-leaf such that the sum of all the node values of each path equals 'S'.",

,Tree DFS Pattern,

"Given a binary tree and a number 'S', find all paths in the tree such that the sum of all the node values of each path equals 'S'. Please note that the paths can start or end at any node but all paths must follow direction from parent to child (top to bottom).",

,Tree DFS Pattern,

"Given a binary tree and a number 'S', find if the tree has a path from root-to-leaf such that the sum of all the node values of that path equals 'S'.",

,Tree DFS Pattern,

"Given a binary tree and a number sequence, find if the sequence is present as a root-to-leaf path in the given tree.",

,Tree DFS Pattern,

"Given a binary tree where each node can only have a digit (0-9) value, each root-to-leaf path will represent a number. Find the total sum of all the numbers represented by all paths.",

,Tree DFS Pattern,

"Given a binary tree, find the length of its diameter. The diameter of a tree is the number of nodes on the longest path between any two leaf nodes. The diameter of a tree may or may not pass through the root.",

,Tree DFS Pattern,

"Design a class to calculate the median of a number stream. The class should have the following two methods: insertNum(int num): stores the number in the class findMedian(): returns the median of all numbers inserted in the class If the count of numbers inserted in the class is even, the median will be the average of the middle two numbers. Example 1: 1. insertNum(3) 2. insertNum(1) 3. findMedian() -> output: 2 4. insertNum(5) 5. findMedian() -> output: 3 6. insertNum(4) 7. findMedian() -> output: 3.5",

,Two Heaps Pattern,

"Given a set of investment projects with their respective profits, we need to find the most profitable projects. We are given an initial capital and are allowed to invest only in a fixed number of projects. Our goal is to choose projects that give us the maximum profit. We can start an investment project only when we have the required capital. Once a project is selected, we can assume that its profit has become our capital. Example 1: Input: Project Capitals=[0,1,2], Project Profits=[1,2,3], Initial Capital=1, Number of Projects=2 Output: 6 Explanation: With the initial capital of '1', we will start the second project which will give us a profit of '2'. Once we selected our first project, our total capital will become 3 (profit + initial capital). With '3' capital, we will select the third project, which will give us '3' profit. After the completion of the two projects, our total capital will be 6 (1+2+3). Example 2: Input: Project Capitals=[0,1,2,3], Project Profits=[1,2,3,5], Initial Capital=0, Number of Projects=3 Output: 8 Explanation: With '0' capital, we can only select the first project, bringing out capital to 1. Next, we will select the second project, which will bring our capital to 3. Next, we will select the fourth project, giving us a profit of 5. After selecting the three projects, our total capital will be 8 (1+2+5).",

,Two Heaps Pattern,

"Given an array of numbers and a number 'k', find the median of all the 'k' sized sub-arrays (or windows) of the array. Example 1: Input: nums=[1, 2, -1, 3, 5], k = 2 Output: [1.5, 0.5, 1.0, 4.0] Explanation: Lets consider all windows of size '2': [1, 2, -1, 3, 5] -> median is 1.5 [1, 2, -1, 3, 5] -> median is 0.5 [1, 2, -1, 3, 5] -> median is 1.0 [1, 2, -1, 3, 5] -> median is 4.0 Example 2: Input: nums=[1, 2, -1, 3, 5], k = 3 Output: [1.0, 2.0, 3.0] Explanation: Lets consider all windows of size '3': [1, 2, -1, 3, 5] -> median is 1.0 [1, 2, -1, 3, 5] -> median is 2.0 [1, 2, -1, 3, 5] -> median is 3.0",

,Two Heaps Pattern,

"Next Interval (hard) Given an array of intervals, find the next interval of each interval. In a list of intervals, for an interval 'i' its next interval 'j' will have the smallest 'start' greater than or equal to the 'end' of 'i'. Write a function to return an array containing indices of the next interval of each input interval. If there is no next interval of a given interval, return -1. It is given that none of the intervals has the same start point. Example 1: Input: Intervals [[2,3], [3,4], [5,6]] Output: [1, 2, -1] Explanation: The next interval of [2,3] is [3,4] having index '1'. Similarly, the next interval of [3,4] is [5,6] having index '2'. There is no next interval for [5,6] hence we have '-1'. Example 2: Input: Intervals [[3,4], [1,5], [4,6]] Output: [2, -1, -1] Explanation: The next interval of [3,4] is [4,6] which has index '2'. There is no next interval for [1,5] and [4,6].",

,Two Heaps Pattern,

"Given a sorted array, create a new array containing squares of all the number of the input array in the sorted order. Example 1: Input: [-2, -1, 0, 2, 3] Output: [0, 1, 4, 4, 9] Example 2: Input: [-3, -1, 0, 1, 2] Output: [0 1 1 4 9]",

,Two Pointers Pattern,

"Given an array arr of unsorted numbers and a target sum, count all triplets in it such that arr[i] + arr[j] + arr[k] < target where i, j, and k are three different indices. Write a function to return the count of such triplets. Example 1: Input: [-1, 0, 2, 3], target=3 Output: 2 Explanation: There are two triplets whose sum is less than the target: [-1, 0, 3], [-1, 0, 2] Example 2: Input: [-1, 4, 2, 1, 3], target=5 Output: 4 Explanation: There are four triplets whose sum is less than the target: [-1, 1, 4], [-1, 1, 3], [-1, 1, 2], [-1, 2, 3]",

,Two Pointers Pattern,

"Given an array containing 0s, 1s and 2s, sort the array in-place. You should treat numbers of the array as objects, hence, we can't count 0s, 1s, and 2s to recreate the array. The flag of the Netherlands consists of three colours: red, white and blue; and since our input array also consists of three different numbers that are why it is called the Dutch National Flag problem. Example 1: Input: [1, 0, 2, 1, 0] Output: [0 0 1 1 2] Example 2: Input: [2, 2, 0, 1, 2, 0] Output: [0 0 1 2 2 2 ]",

,Two Pointers Pattern,

"Given an array of sorted numbers and a target sum, find a pair in the array whose sum is equal to the given target. Write a function to return the indices of the two numbers (i.e. the pair) such that they add up to the given target. Example 1: Input: [1, 2, 3, 4, 6], target=6 Output: [1, 3] Explanation: The numbers at index 1 and 3 add up to 6: 2+4=6 Example 2: Input: [2, 5, 9, 11], target=11 Output: [0, 2] Explanation: The numbers at index 0 and 2 add up to 11: 2+9=11",

,Two Pointers Pattern,

"Given an array of sorted numbers, remove all duplicates from it. You should not use any extra space; after removing the duplicates in-place return the new length of the array. Example 1: Input: [2, 3, 3, 3, 6, 9, 9] Output: 4 Explanation: The first four elements after removing the duplicates will be [2, 3, 6, 9]. Example 2: Input: [2, 2, 2, 11] Output: 2 Explanation: The first two elements after removing the duplicates will be [2, 11].",

,Two Pointers Pattern,

"Given an array of unsorted numbers and a target number, find a triplet in the array whose sum is as close to the target number as possible, return the sum of the triplet. If there is more than one such triplet, return the sum of the triplet with the smallest sum. Example 1: Input: [-2, 0, 1, 2], target=2 Output: 1 Explanation: The triplet [-2, 1, 2] has the closest sum to the target. Example 2: Input: [-3, -1, 1, 2], target=1 Output: 0 Explanation: The triplet [-3, 1, 2] has the closest sum to the target. Example 3: Input: [1, 0, 1, 1], target=100 Output: 3 Explanation: The triplet [1, 1, 1] has the closest sum to the target.",

,Two Pointers Pattern,

"Given an array of unsorted numbers and a target number, find all unique quadruplets in it, whose sum is equal to the target number. Example 1: Input: [4, 1, 2, -1, 1, -3], target=1 Output: [-3, -1, 1, 4], [-3, 1, 1, 2] Explanation: Both the quadruplets add up to the target. Example 2: Input: [2, 0, -1, 1, -2, 2], target=2 Output: [-2, 0, 2, 2], [-1, 0, 1, 2] Explanation: Both the quadruplets add up to the target.",

,Two Pointers Pattern,

"Given an array of unsorted numbers, find all unique triplets in it that add up to zero. Example 1: Input: [-3, 0, 1, 2, -1, 1, -2] Output: [-3, 1, 2], [-2, 0, 2], [-2, 1, 1], [-1, 0, 1] Explanation: There are four unique triplets whose sum is equal to zero. Example 2: Input: [-5, 2, -1, -2, 3] Output: [[-5, 2, 3], [-2, -1, 3]] Explanation: There are two unique triplets whose sum is equal to zero.",

,Two Pointers Pattern,

"Given an array with positive numbers and a target number, find all of its contiguous subarrays whose product is less than the target number. Example 1: Input: [2, 5, 3, 10], target=30 Output: [2], [5], [2, 5], [3], [5, 3], [10] Explanation: There are six contiguous subarrays whose product is less than the target. Example 2: Input: [8, 2, 6, 5], target=50 Output: [8], [2], [8, 2], [6], [2, 6], [5], [6, 5] Explanation: There are seven contiguous subarrays whose product is less than the target.",

,Two Pointers Pattern,

"Given an array, find the length of the smallest subarray in it which when sorted will sort the whole array. Example 1: Input: [1, 2, 5, 3, 7, 10, 9, 12] Output: 5 Explanation: We need to sort only the subarray [5, 3, 7, 10, 9] to make the whole array sorted Example 2: Input: [1, 3, 2, 0, -1, 7, 10] Output: 5 Explanation: We need to sort only the subarray [1, 3, 2, 0, -1] to make the whole array sorted Example 3: Input: [1, 2, 3] Output: 0 Explanation: The array is already sorted Example 4: Input: [3, 2, 1] Output: 3 Explanation: The whole array needs to be sorted",

,Two Pointers Pattern,

"Given two strings containing backspaces (identified by the character '#'), check if the two strings are equal. Example 1: Input: str1=""xy#z"", str2=""xzz#"" Output: true Explanation: After applying backspaces the strings become ""xz"" and ""xz"" respectively. Example 2: Input: str1=""xy#z"", str2=""xyz#"" Output: false Explanation: After applying backspaces the strings become ""xz"" and ""xy"" respectively. Example 3: Input: str1=""xp#"", str2=""xyz##"" Output: true Explanation: After applying backspaces the strings become ""x"" and ""x"" respectively. In ""xyz##"", the first '#' removes the character 'z' and the second '#' removes the character 'y'. Example 4: Input: str1=""xywrrmp"", str2=""xywrrmu#p"" Output: true Explanation: After applying backspaces the strings become ""xywrrmp"" and ""xywrrmp"" respectively.",

,Two Pointers Pattern,


Kaugnay na mga set ng pag-aaral

Rational Decision Making Process

View Set

Social Studies Chapter 16 Section 2 Quiz

View Set

Python Programming DiSSS Phase 1 - Lists/Tuples

View Set

Human Growth and Development Midterm

View Set

Penny Chapter 27 Fetal Heart and Chest

View Set

Prep U Chapter 34: Assessment and Management of Patients with Inflammatory Rheumatic Disorders

View Set