jayati tiwari
jayati tiwari
  • Видео 56
  • Просмотров 528 183
Leetcode 986. Interval List Intersections [Algo + Code + Time/Space Complexity]
One of the most frequently asked coding interview questions on Arrays in companies like Google, Facebook, Amazon, LinkedIn, Microsoft, Uber, Apple, Adobe, Bloomberg etc.
LeetCode : Interval List Intersections
Problem URL - leetcode.com/problems/interval-list-intersections/
Question : Given two lists of closed intervals, each list of intervals is pairwise disjoint and in sorted order.
Return the intersection of these two interval lists.
Example 1:
Input: A = [[0,2],[5,10],[13,23],[24,25]], B = [[1,5],[8,12],[15,24],[25,26]]
Output: [[1,2],[5,5],[8,10],[15,23],[24,24],[25,25]]
Connect with me on LinkedIn at: www.linkedin.com/in/jayati-tiwari/
#leetcode, #coding, #algorithms, #facebook, #leetcode986...
Просмотров: 5 094

Видео

Leetcode 435. Non Overlapping Intervals [Algo + Code + Time/Space Complexity]
Просмотров 4,3 тыс.3 года назад
One of the most frequently asked coding interview questions on Arrays in companies like Google, Facebook, Amazon, LinkedIn, Microsoft, Uber, Apple, Adobe, Bloomberg etc. LeetCode : Non-overlapping Intervals Problem URL - leetcode.com/problems/non-overlapping-intervals/ Question : Given a collection of intervals, find the minimum number of intervals you need to remove to make the rest of the int...
Leetcode 253. Meeting Rooms II [Algo + Code + Time/Space Complexity]
Просмотров 14 тыс.3 года назад
One of the most frequently asked coding interview questions on Arrays in companies like Google, Facebook, Amazon, LinkedIn, Microsoft, Uber, Apple, Adobe, Bloomberg etc. LeetCode : Meeting Rooms II Problem URL - leetcode.com/problems/meeting-rooms-ii/ Time complexity - O(N * log N) Space Complexity - O(N) where N is length of given input array. Question : Given an array of meeting time interval...
Leetcode 252. Meeting Rooms [Algorithm + Code + Time Complexity]
Просмотров 10 тыс.3 года назад
One of the most frequently asked coding interview questions on Array in companies like Google, Facebook, Amazon, LinkedIn, Microsoft, Uber, Apple, Adobe, bloomberg etc. LeetCode : Meeting Rooms Problem URL - leetcode.com/problems/meeting-rooms/ Time complexity - O(N * log N) Space Complexity - O(1) where N is length of given input array. Question :Given an array of meeting time intervals where ...
Leetcode 90. Subsets II [ Backtracking Algorithm + Code Explained] TC - O(N * 2^N)
Просмотров 10 тыс.4 года назад
One of the most frequently asked coding interview questions on Array in companies like Google, Facebook, Amazon, LinkedIn, Microsoft, Uber, Apple, Adobe, bloomberg etc. LeetCode : Subsets II Problem URL - leetcode.com/problems/subsets-ii/ Time complexity - O(N * 2^N) Details - O(2^N) - To generate all subsets O(N) - For copying them into output list. Space Complexity - O(N * 2^N) to keep all th...
Leetcode 78. Subsets [ Backtracking Algorithm + Code Explained] TC - O( N * 2^N)
Просмотров 18 тыс.4 года назад
One of the most frequently asked coding interview questions on Array in companies like Google, Facebook, Amazon, LinkedIn, Microsoft, Uber, Apple, Adobe etc. LeetCode : Subsets Problem URL - leetcode.com/problems/subsets/ Time complexity - O(N * 2^N) Details - O(2^N) - To generate all subsets O(N) - For copying them into output list. Space Complexity - O(N * 2^N) to keep all the subsets of leng...
Leetcode 122. Best Time to Buy and Sell Stock II [ Algorithm + Code Explained]
Просмотров 4,5 тыс.4 года назад
One of the most frequently asked coding interview questions on Array in companies like Google, Facebook, Amazon, LinkedIn, Fintech firm like Morgan Stanley, Goldman, J P Morgan, Microsoft, Uber, Apple, Adobe etc. LeetCode : Best Time to Buy and Sell Stock II Problem URL - leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/ Question :Say you have an array prices for which the ith element i...
Leetcode 188. Best Time to Buy and Sell Stock IV [ Algorithm + Code Explained]
Просмотров 14 тыс.4 года назад
One of the most frequently asked coding interview questions on Array in companies like Google, Facebook, Amazon, LinkedIn, Fintech firm like Morgan Stanley, Goldman, J P Morgan, Microsoft, Uber, Apple, Adobe etc. LeetCode : Best Time to Buy and Sell Stock IV Problem URL - leetcode.com/problems/best-time-to-buy-and-sell-stock-iv/ Question :Say you have an array for which the i-th element is the ...
Leetcode 123. Best Time to Buy and Sell Stock III [ Algorithm + Code Explained]
Просмотров 27 тыс.4 года назад
One of the most frequently asked coding interview questions on Array in companies like Google, Facebook, Amazon, LinkedIn, Fintech firm like Morgan Stanley, Goldman, J P Morgan, Microsoft, Uber, Apple, Adobe etc. LeetCode : Best Time to Buy and Sell Stock III Problem URL - leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/ Question :Say you have an array for which the ith element is the...
Leetcode 714. Best Time to Buy and Sell Stock with Transaction Fee [ Algorithm + Code Explained]
Просмотров 11 тыс.4 года назад
One of the most frequently asked coding interview questions on Array in companies like Google, Facebook, Amazon, LinkedIn, Fintech firm like Morgan Stanley, Goldman, J P Morgan, Microsoft, Uber, Apple, Adobe etc. LeetCode : Best Time to Buy and Sell Stock with Transaction Fee Problem URL - leetcode.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee/ Question :Your are given an ar...
Leetcode 309. Best Time to Buy and Sell Stock with Cooldown [ Algorithm + Code Explained]
Просмотров 18 тыс.4 года назад
One of the most frequently asked coding interview questions on Array in companies like Google, Facebook, Amazon, LinkedIn, Fintech firm like Morgan Stanley, Goldman, J P Morgan, Microsoft, Uber, Apple, Adobe etc. LeetCode : Best Time to Buy and Sell Stock with Cooldown Problem URL - leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/ Time complexity - O(n) Space Complexity - 0(...
LeetCode 23. Merge k Sorted Lists[ Algorithm + Code Explained]
Просмотров 8 тыс.4 года назад
One of the most frequently asked coding interview questions on Linked List in companies like Google, Facebook, Amazon, LinkedIn, Microsoft, Uber, Apple, Adobe etc. LeetCode : Merge k Sorted Lists Problem URL - leetcode.com/problems/merge-k-sorted-lists/ Question :Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Example: Input: [ 1-4-5, 1-3-4, 2-...
LeetCode 221. Maximal Square [ Algorithm + Code Explained]
Просмотров 3,3 тыс.4 года назад
One of the most frequently asked coding interview questions on 2D Array in companies like Google, Facebook, Amazon, LinkedIn, Microsoft, Uber, Apple, Adobe etc. LeetCode : Maximal Square Problem URL - leetcode.com/problems/maximal-square/ Question :Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area. Example: Input: 1 0 1 0 0 1 0 1 1...
LeetCode 312. Burst Balloons[ Algorithm + Code Explained]
Просмотров 8 тыс.4 года назад
One of the most frequently asked coding interview questions on Arrays in companies like Google, Facebook, Amazon, LinkedIn, Microsoft, Uber, Apple, Adobe etc. LeetCode : Burst Balloons Problem URL - leetcode.com/problems/burst-balloons/ Question :Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the balloon...
LeetCode 226. Invert Binary Tree[ Solution + Code Explained] Mirror Tree
Просмотров 2,9 тыс.4 года назад
One of the most frequently asked coding interview questions on Tree in companies like Google, Facebook, Amazon, LinkedIn, Microsoft, Uber, Apple, Adobe etc. URL - leetcode.com/problems/invert-binary-tree/ LeetCode : Invert Binary Tree Question : Invert a binary tree. Example: Input: 4 / \ 2 7 / \ / \ 1 3 6 9 Output: 4 / \ 7 2 / \ / \ 9 6 3 1 Trivia: This problem was inspired by this original tw...
LeetCode 85. Maximal Rectangle [ Solution + Code Explained]
Просмотров 13 тыс.4 года назад
LeetCode 85. Maximal Rectangle [ Solution Code Explained]
LeetCode 84. Largest Rectangle in Histogram[ Solution + Code Explained]
Просмотров 21 тыс.4 года назад
LeetCode 84. Largest Rectangle in Histogram[ Solution Code Explained]
Leetcode 283. Move Zeroes [ Solution + Code Explained]
Просмотров 5 тыс.4 года назад
Leetcode 283. Move Zeroes [ Solution Code Explained]
Leetcode 581. Shortest Unsorted Continuous Subarray [ Solution + Code Explained]
Просмотров 4,5 тыс.4 года назад
Leetcode 581. Shortest Unsorted Continuous Subarray [ Solution Code Explained]
Leetcode 448. Find All Numbers Disappeared in an Array [ Solution + Code Explained]
Просмотров 12 тыс.4 года назад
Leetcode 448. Find All Numbers Disappeared in an Array [ Solution Code Explained]
LeetCode 437. Path Sum III [Solution + Code Explained ]
Просмотров 21 тыс.4 года назад
LeetCode 437. Path Sum III [Solution Code Explained ]
LeetCode 617. Merge Two Binary Trees [Solution + Code Explained ]
Просмотров 8 тыс.4 года назад
LeetCode 617. Merge Two Binary Trees [Solution Code Explained ]
LeetCode 543. Diameter of Binary Tree [Solution + Code Explained ]
Просмотров 12 тыс.4 года назад
LeetCode 543. Diameter of Binary Tree [Solution Code Explained ]
LeetCode 169. Majority Element [Solution + Code Explained ]
Просмотров 3,7 тыс.4 года назад
LeetCode 169. Majority Element [Solution Code Explained ]
LeetCode 75. Sort Colors [Solution + Code Explained ]
Просмотров 4,8 тыс.4 года назад
LeetCode 75. Sort Colors [Solution Code Explained ]
LeetCode 394. Decode String [Solution + Code Explained ]
Просмотров 18 тыс.4 года назад
LeetCode 394. Decode String [Solution Code Explained ]
LeetCode 234. Palindrome Linked List [Solution + Code Explained ]
Просмотров 10 тыс.4 года назад
LeetCode 234. Palindrome Linked List [Solution Code Explained ]
LeetCode 101. Symmetric Tree [Solution + Code Explained ]
Просмотров 6 тыс.4 года назад
LeetCode 101. Symmetric Tree [Solution Code Explained ]
LeetCode 105. Construct Binary Tree from Preorder and Inorder Traversal [Solution + Code Explained ]
Просмотров 14 тыс.4 года назад
LeetCode 105. Construct Binary Tree from Preorder and Inorder Traversal [Solution Code Explained ]
LeetCode 62. Unique Paths [Solution + Code Explained ]
Просмотров 2,8 тыс.4 года назад
LeetCode 62. Unique Paths [Solution Code Explained ]

Комментарии

  • @navintiwari
    @navintiwari 14 дней назад

    To anyone who is still finding it difficult to understand, following might help. The idea is to keep track of max profit by end of each day (ith day) when you have completed one or more of following transactions so far (by the end of ith day): 1. You buy for the first time: fb -> profit after first buy (first buy up until the ith day). 2. You sell for the first time: fs -> profit after first sell ((first sell up until the ith day)). 3. You buy for the second time: sb -> proft after second buy (second buy up until the ith day). 4. You sell for the second time: ss -> profit after second sell (second sell up until the ith day). The profit after first buy (fb) up until the ith day will be the max of i) The profit if you buy for the first time on the ith day i.e., -prices[i]. ii) The fb profit seen so far up until the (i-1)th day (you are keeping a running max, so one variable(fb) is enough to keep track of it) The profit after first sell (fs) up until the ith day will be the max of i) profit if you sell for the first time on ith day. This will also depend on the profit due to first buy up until the ith day. So fs = fb + prices[i] ii) the fs profit seen so far up until the (i-1)th day (you are keeping a running max, using fs variable only) Similarly, the profits for sb and ss would depend on fs and sb respectively. Hope it helps. Please don't hesitate to reply if you have any questions. :)

  • @vasuarora_
    @vasuarora_ 17 дней назад

    Woww What a video!! I really liked your simple solution and explanation.I saw many youtubers video of this same question including Striver and more but you just explaiend the solution simply in 11 minutes.

  • @LordSarcasticVlogger
    @LordSarcasticVlogger 27 дней назад

    You are so beautiful 😍😍 Are you single dear?😍😊

  • @vinamrasangal8436
    @vinamrasangal8436 Месяц назад

    recursion hi likh deti !!

  • @Amriteshrajgupta69
    @Amriteshrajgupta69 Месяц назад

    sundar thi issi liye aa gya video dekhne waise mujhe java aati bhi nhi hai phir bhi pura dekh liya ❤😊

  • @theja63
    @theja63 Месяц назад

    The fact that you don't follow a step by step manner from naive to optimal shows your incompetence (at least in teaching).

  • @abhisheks3242
    @abhisheks3242 2 месяца назад

    Very impressive solution:)

  • @hannanhub1717
    @hannanhub1717 5 месяцев назад

    Thanks 👍

  • @piyushsoni6109
    @piyushsoni6109 5 месяцев назад

    You may need to use digital pen for better explanation just a suggestion

  • @geekyNib
    @geekyNib 5 месяцев назад

    Amazing Way to Teach, Mam, pls provide slide u shared at 1:23, it would be very helpful.

  • @theblueplanet3576
    @theblueplanet3576 6 месяцев назад

    Why not just do the number to string conversion in the sort method? That will avoid the first loop over the entire number list. 🤔

  • @shubhamkumar-hx1fb
    @shubhamkumar-hx1fb 7 месяцев назад

    this method is not intuitive...dp solution is more intuitive and then convert that solution to sapce optimization

  • @TrungNguyen-eo7qz
    @TrungNguyen-eo7qz 7 месяцев назад

    How to find and return the indices of best day to buy and best day to sell with max profit?

  • @mayappapujari9259
    @mayappapujari9259 8 месяцев назад

    great...

  • @504rishukumar4
    @504rishukumar4 8 месяцев назад

    for a newly added test case. Plz use(int temp) as( long temp) and in helper function (int sum) as (long sum).

  • @mugiwaranoDave
    @mugiwaranoDave 8 месяцев назад

    In the first example, given that the root value is 10 and target sum is 8, how is it possible that we have 3 results? If we travel downwards and keep track of the path, then sum will never be 8 (target sum) simply because 10 (root value) is greater than 8 (target sum). The only solution I can think of is summing up the path upwards, which goes against the description: Quote from description: 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). What am I missing here?

  • @intromaker400
    @intromaker400 9 месяцев назад

    Mam please explain more questions.on graph ,linkedlist ,stack and dp which asked in mid and top level companies in java

  • @mohamedhussien4013
    @mohamedhussien4013 10 месяцев назад

    Thank u so much. I didn't take a look at you code just I saw the commented instructions and solved the problem. Not always to think recursively.

  • @Sovit705
    @Sovit705 11 месяцев назад

    And we were fools to use DP solutions. This solution is best

  • @rounaq_khandelwal
    @rounaq_khandelwal Год назад

    Can we use 2 pointers instead of a priority queue in the sorted intervals, ( we can maintain a counter which keeps on incrementing as long as we are having clashed meetings consecutively, else re initialize it with 1 while iterating in the intervals array )

  • @karanbhanushali6756
    @karanbhanushali6756 Год назад

    Your code passed all the test cases on very first trial you are a genius

  • @codemarshal655
    @codemarshal655 Год назад

    We can solve all variations of stock buy sell with this 1 code. ruclips.net/video/G_BICqMdoYU/видео.html

  • @codemarshal655
    @codemarshal655 Год назад

    We can solve all variations of stock buy sell with this 1 code. ruclips.net/video/G_BICqMdoYU/видео.html

  • @codemarshal655
    @codemarshal655 Год назад

    We can solve all variations of stock buy sell with this 1 code. ruclips.net/video/G_BICqMdoYU/видео.html

  • @codemarshal655
    @codemarshal655 Год назад

    We can solve all variations of stock buy sell with this 1 code. ruclips.net/video/G_BICqMdoYU/видео.html

  • @pawxnsingh
    @pawxnsingh Год назад

    This is Even Best for C++ users I modified it Little Bit class Solution { public: int minMeetingRoom(vector<vector<int>>meetingTime) { sort(meetingTime.begin(),meetingTime.end()); priority_queue<int,vector<int>,greater<int>> pq; pq.push(meetingTime[0][1]); for(int i=1;i<meetingTime.size();i++) { if(meetingTime[i][0] >= pq.top()) { pq.pop(); } pq.push(meetingTime[i][1]); } return pq.size(); } };

  • @RahulKumar-zp1ln
    @RahulKumar-zp1ln Год назад

    full confuse🙂

  • @fourieruddin871
    @fourieruddin871 Год назад

    You are the best till now.

  • @pran7119
    @pran7119 Год назад

    Awful!

  • @shashanksingh4708
    @shashanksingh4708 Год назад

    why do we have to sort on the basis of start time ?

  • @dontignore5567
    @dontignore5567 Год назад

    Why Summation of dp[i-1] and dp[i-2] that I cannot understand.

  • @pedrohenriqueleite9382
    @pedrohenriqueleite9382 Год назад

    why have to put +1 when we return max of L,R?

  • @sourabh258
    @sourabh258 Год назад

    A simpler version could be: public int eraseOverlapIntervals(int[][] intervals) { Arrays.sort(intervals,(a,b) -> a[0]-b[0]); int end=intervals[0][1], res=0; for(int i=1;i<intervals.length;i++) if(intervals[i][0]<end){ end=Math.min(end,intervals[i][1]); res++; }else end=intervals[i][1]; return res; }

  • @sourabh258
    @sourabh258 Год назад

    A simpler version with the same approach can be: public int minMeetingRooms(List<Interval> intervals) { if(intervals.size()<=1) return intervals.size(); PriorityQueue<Integer> pq = new PriorityQueue<>(); intervals.sort((a,b) -> Integer.compare(a.start,b.start)); pq.add(intervals.get(0).end); for(int i=1;i<intervals.size();i++){ if(pq.peek() <= intervals.get(i).start) pq.poll(); pq.add(intervals.get(i).end); } return pq.size(); }

  • @jjque322
    @jjque322 Год назад

    So beautiful the teacher 😉

  • @EricSamuel-xh2yb
    @EricSamuel-xh2yb Год назад

    why do you need the has?

  • @mrprime557
    @mrprime557 Год назад

    wooow officially the worst explanation on RUclips....

  • @kartiksharma674
    @kartiksharma674 Год назад

    Can someone post solution in cpp with the same logic

  • @hugovera1540
    @hugovera1540 Год назад

    thank you so much for teaching us this problem. A recruiter that does not like me will ask why is it so slow? why is 90% of other submissions faster? I'll resaearch it! is there a book besides cracking the interview? Your so kind for putting a solution to this problem that is common to asked in an interview

  • @joyal7701
    @joyal7701 Год назад

    noice

  • @abhayrai1724
    @abhayrai1724 Год назад

    Thank you ✨

  • @PsychonauticResearch
    @PsychonauticResearch Год назад

    implementation in ruby ``` def add_two_numbers(l1, l2) pointer_to_head = ListNode.new # dummy tail = pointer_to_head local_sum = 0 until l1.nil? && l2.nil? && local_sum == 0 if l1 local_sum += l1.val l1 = l1.next end if l2 local_sum += l2.val l2 = l2.next end tail.next = ListNode.new local_sum % 10 # hook up local_sum = local_sum / 10 # serves as a carryover tail = tail.next # reassign running pointer to the newly created node end pointer_to_head.next end ```

  • @PsychonauticResearch
    @PsychonauticResearch Год назад

    guys, marry this type of women.

  • @manishapandey9931
    @manishapandey9931 Год назад

    Thank You !

  • @ShauryaVlogX
    @ShauryaVlogX Год назад

    thhoda hindi me hi bol deti didi...ye itna jyada technical word kahogi to kaha se smjh aaega ....ham log khud yaha seekhne aae hain.

  • @tingtingwang5490
    @tingtingwang5490 Год назад

    The easiest and fast solution that i found on youtube thank you very much!

  • @prabingupta7438
    @prabingupta7438 Год назад

    Why don't you explain the problem in notepad or graphical form. It would be helpful for beginer like us instead just speaking and explaining. ??

  • @rabindrapatra7151
    @rabindrapatra7151 Год назад

    5/5

  • @rabindrapatra7151
    @rabindrapatra7151 Год назад

    without using pen and paper she explained it and I can write it easily.

  • @rabindrapatra7151
    @rabindrapatra7151 Год назад

    amazing. calm and simple explanation. no over confidence. better than DSA gurus.