title
Rotate Array by K places | Union, Intersection of Sorted Arrays | Move Zeros to End | Arrays Part-2

description
Notes/C++/Java/Python codes in Step 3.1 of https://bit.ly/tufA2ZYt Left Rotate array by 1 place: https://takeuforward.org/data-structure/left-rotate-the-array-by-one/ Left Rotate array by D places: https://takeuforward.org/arrays/left-rotate-an-array-by-d-places/ Right Rotate array by d places: https://takeuforward.org/arrays/right-rotate-an-array-by-d-places/ Move zeros to End: https://takeuforward.org/data-structure/move-all-zeros-to-the-end-of-the-array/ Linear Search: https://takeuforward.org/arrays/linear-search-algorithm/ Union of two sorted Arrays: https://takeuforward.org/data-structure/union-of-two-sorted-arrays/ The intersection of two sorted arrays: https://takeuforward.org/data-structure/intersection-of-two-sorted-arrays/ Problem links Left Rotate array by 1 place: https://bit.ly/3ZeXGrO Left Rotate array by K places: http://bit.ly/3IQQdrt Move zeros to End: https://bit.ly/3XbsF6k Linear Search: https://bit.ly/3GmcVGJ Union of two sorted Arrays: https://bit.ly/3IpS7Rd Intersection of two sorted arrays: http://bit.ly/3KSSx3Z We have solved the above problems, and we have gone from brute force and ended with the most optimal solution. Full Course: https://bit.ly/tufA2ZYt You can follow me across social media, all my handles are below: Linkedin/Instagram/Telegram: https://linktr.ee/takeUforward 0:00 Introduction of course 01:01 Left rotate an Array by 1 Place 07:17 Code-compiler (Left rotate an Array by 1 Place) 08:05 Left rotate an Array by D Places 20:18 Code-compiler (Left rotate an Array by D Places ) 27:13 Move zeroes to end 40:30 Code-compiler (Move zeroes to end ) 41:05 Linear search 42:43 Code-compiler (Linear search ) 43:04 Union of two sorted array 53:33 Code-compiler (Union of two sorted array) 59:05 Intersection of two sorted array 1:09:30 Code-compiler (Intersection of two sorted array)

detail
{'title': 'Rotate Array by K places | Union, Intersection of Sorted Arrays | Move Zeros to End | Arrays Part-2', 'heatmap': [{'end': 1013.089, 'start': 960.785, 'weight': 0.703}, {'end': 1279.712, 'start': 1143.376, 'weight': 0.713}, {'end': 1455.299, 'start': 1404.213, 'weight': 0.776}, {'end': 1585.347, 'start': 1537.655, 'weight': 1}, {'end': 2157.846, 'start': 2065.853, 'weight': 0.965}, {'end': 2336.761, 'start': 2240.513, 'weight': 0.757}, {'end': 2904.138, 'start': 2857.805, 'weight': 0.889}, {'end': 3342.133, 'start': 3253.078, 'weight': 0.744}, {'end': 3476.083, 'start': 3385.305, 'weight': 0.785}, {'end': 3562.777, 'start': 3516.642, 'weight': 0.8}], 'summary': 'Covers a2z dsa course with 456 modules, 400+ problems, and interview preparation tips, explores left rotation array problem with time and space complexity, logic behind array rotation, and moving zeros to the end, discusses union and intersection of sorted arrays with optimal approaches, and provides detailed examples and time and space complexity analysis.', 'chapters': [{'end': 445.557, 'segs': [{'end': 48.839, 'src': 'embed', 'start': 24.071, 'weight': 0, 'content': [{'end': 32.634, 'text': 'we will be covering 456 modules and we will be solving 400 plus problems in this ds algo course.', 'start': 24.071, 'duration': 8.563}, {'end': 40.396, 'text': 'so when you end this course you can actually clear any of the ds algorithms in any of the interviews in any part of the world.', 'start': 32.634, 'duration': 7.762}, {'end': 48.839, 'text': 'so till now we have covered till step 3.1, fourth problem, and in this video we will be covering these five problems.', 'start': 40.396, 'duration': 8.443}], 'summary': '456 modules, 400+ problems in ds algo course, covering step 3.1 and five problems.', 'duration': 24.768, 'max_score': 24.071, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U24071.jpg'}, {'end': 100.17, 'src': 'embed', 'start': 68.435, 'weight': 1, 'content': [{'end': 71.456, 'text': 'given that the Brute and Better exist for that problem.', 'start': 68.435, 'duration': 3.021}, {'end': 74.738, 'text': 'And this is the way you should always tell in an interview.', 'start': 71.917, 'duration': 2.821}, {'end': 81.661, 'text': "Why? Because in an interview, your thought process should be visible to the interviewer because it's you who will be driving the interview.", 'start': 74.798, 'duration': 6.863}, {'end': 90.685, 'text': 'So make sure you follow this particular step by step optimization of approaches because it does leave a very positive impact on the interviewer.', 'start': 81.901, 'duration': 8.784}, {'end': 91.946, 'text': 'Now, coming back to the problem.', 'start': 90.965, 'duration': 0.981}, {'end': 94.447, 'text': 'left rotate the array by one place.', 'start': 92.526, 'duration': 1.921}, {'end': 95.348, 'text': 'what does it mean?', 'start': 94.447, 'duration': 0.901}, {'end': 97.789, 'text': 'so, given an array, you have to left rotate it.', 'start': 95.348, 'duration': 2.441}, {'end': 100.17, 'text': 'yes, you have to left rotate it by one place.', 'start': 97.789, 'duration': 2.381}], 'summary': 'In an interview, showcase step-by-step optimization of approaches for a positive impact on the interviewer.', 'duration': 31.735, 'max_score': 68.435, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U68435.jpg'}, {'end': 411.926, 'src': 'embed', 'start': 380.078, 'weight': 3, 'content': [{'end': 382.919, 'text': 'so understand the shuttle difference.', 'start': 380.078, 'duration': 2.841}, {'end': 390.141, 'text': "if someone says in the algorithm you should always take the space that you are being used like that's being used,", 'start': 382.919, 'duration': 7.222}, {'end': 395.742, 'text': "and if someone says what's the extra space, then you can say so there's a shuttle difference.", 'start': 390.141, 'duration': 5.601}, {'end': 398.923, 'text': 'whenever you go to an interview, always clarify it.', 'start': 395.742, 'duration': 3.181}, {'end': 402.064, 'text': 'tell them that so the extra spaces.', 'start': 398.923, 'duration': 3.141}, {'end': 404.805, 'text': 'so whenever you go to an interview, always clarify this.', 'start': 402.064, 'duration': 2.741}, {'end': 411.926, 'text': "tell them, sir or ma'am, the extra space that i'm using is b co fun, but in order to solve this problem i'm using this array.", 'start': 404.805, 'duration': 7.121}], 'summary': 'Clarify shuttle difference in algorithm interviews to avoid confusion.', 'duration': 31.848, 'max_score': 380.078, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U380078.jpg'}], 'start': 3.291, 'title': 'Dsa course & left rotation problem', 'summary': 'Covers a2z dsa course with 456 modules, 400+ problems, and a focus on interview preparation, alongside a detailed exploration of left rotation array problem with emphasis on time and space complexity, and interview tips.', 'chapters': [{'end': 81.661, 'start': 3.291, 'title': 'A2z dsa course: in-depth ds algo training', 'summary': 'Discusses the a2z dsa course, covering 456 modules and solving 400+ problems, aiming to equip learners to clear any ds algorithm interview globally, with a focus on problem-solving techniques and thought process transparency.', 'duration': 78.37, 'highlights': ['The A2Z DSA course covers 456 modules and aims to solve 400+ problems, ensuring learners are well-prepared for DS algorithm interviews globally.', 'The course emphasizes problem-solving techniques, starting with Brute, progressing to Better, and finally reaching Optimal solutions, with a focus on showcasing the thought process in interviews.', 'The chapter emphasizes the importance of transparent thought process during interviews and encourages learners to articulate their problem-solving approach effectively.']}, {'end': 445.557, 'start': 81.901, 'title': 'Left rotation array problem', 'summary': 'Discusses left rotation of an array by one place, providing a step-by-step approach to solve the problem, emphasizing the time and space complexity as o(n) and o(1) respectively, and advising on clarifying space usage in interviews.', 'duration': 363.656, 'highlights': ['The chapter provides a step-by-step approach to solve the left rotation array problem, emphasizing the time complexity of O(n) due to running a loop for n times and space complexity of O(1) as no extra space is used.', 'The chapter advises on clarifying space usage in interviews, explaining the difference between using the given array and any extra space, in order to present concepts clearly and impress the interviewer.', 'The chapter emphasizes the importance of driving interviews by clearly presenting concepts to impress interviewers, ensuring crystal clear communication of all aspects of the solution.']}], 'duration': 442.266, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U3291.jpg', 'highlights': ['The A2Z DSA course covers 456 modules and aims to solve 400+ problems, ensuring learners are well-prepared for DS algorithm interviews globally.', 'The course emphasizes problem-solving techniques, starting with Brute, progressing to Better, and finally reaching Optimal solutions, with a focus on showcasing the thought process in interviews.', 'The chapter provides a step-by-step approach to solve the left rotation array problem, emphasizing the time complexity of O(n) due to running a loop for n times and space complexity of O(1) as no extra space is used.', 'The chapter advises on clarifying space usage in interviews, explaining the difference between using the given array and any extra space, in order to present concepts clearly and impress the interviewer.', 'The chapter emphasizes the importance of transparent thought process during interviews and encourages learners to articulate their problem-solving approach effectively.']}, {'end': 748.687, 'segs': [{'end': 561.863, 'src': 'embed', 'start': 487.23, 'weight': 3, 'content': [{'end': 490.833, 'text': 'It states you to left rotate the array, but this time by d places.', 'start': 487.23, 'duration': 3.603}, {'end': 494.636, 'text': 'Assuming for this given example array, we have d equal to 2.', 'start': 491.493, 'duration': 3.143}, {'end': 498.959, 'text': "So it's stating that left rotated by two places.", 'start': 494.636, 'duration': 4.323}, {'end': 506.703, 'text': 'so these two elements should be left rotated and these elements should be moved by two places.', 'start': 498.959, 'duration': 7.744}, {'end': 508.825, 'text': 'this is what you mean by left rotation.', 'start': 506.703, 'duration': 2.122}, {'end': 517.71, 'text': 'so if i do that, the resultant array will be three, four, five, six, seven and then one and two.', 'start': 508.825, 'duration': 8.885}, {'end': 524.733, 'text': 'so this one and two kind of moves here and then moves here, and these will move two places ahead.', 'start': 517.71, 'duration': 7.023}, {'end': 530.696, 'text': 'so this is what the resultant array will be after you have left rotated the array by d places.', 'start': 524.733, 'duration': 5.963}, {'end': 532.376, 'text': 'd over here is two.', 'start': 530.696, 'duration': 1.68}, {'end': 533.617, 'text': 'd could have been three.', 'start': 532.376, 'duration': 1.241}, {'end': 535.818, 'text': 'yes, d could have been three as well.', 'start': 533.617, 'duration': 2.201}, {'end': 537.899, 'text': 'in case of three, what would have been the answer?', 'start': 535.818, 'duration': 2.081}, {'end': 539.059, 'text': 'Yes, obviously.', 'start': 538.399, 'duration': 0.66}, {'end': 545.58, 'text': 'In that case, 1, 2, 3 would have been left rotated and they would have been moving by three places ahead.', 'start': 539.619, 'duration': 5.961}, {'end': 551.299, 'text': 'So in that case, the answer would have been 4, 5, 6, 7, and then 1, 2, 3.', 'start': 545.96, 'duration': 5.339}, {'end': 555.022, 'text': "So that's the answer for D equal to 3.", 'start': 551.301, 'duration': 3.721}, {'end': 558.983, 'text': "Now, what if? Yes, what if? Like, let's count the size of the array.", 'start': 555.022, 'duration': 3.961}, {'end': 561.863, 'text': "It's like 1, sorry, my bad.", 'start': 559.443, 'duration': 2.42}], 'summary': 'Left rotate array by d places, d=2: 3,4,5,6,7,1,2. d=3: 4,5,6,7,1,2,3.', 'duration': 74.633, 'max_score': 487.23, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U487230.jpg'}, {'end': 687.923, 'src': 'embed', 'start': 640.844, 'weight': 0, 'content': [{'end': 644.586, 'text': 'so can i see multiple of seven rotations can be done.', 'start': 640.844, 'duration': 3.742}, {'end': 648.687, 'text': 'it will always bring you back to the original array.', 'start': 646.345, 'duration': 2.342}, {'end': 654.232, 'text': 'I repeat, multiple of seven rotations will always bring you to the original array.', 'start': 649.007, 'duration': 5.225}, {'end': 657.034, 'text': 'The remaining is what you need to do.', 'start': 654.792, 'duration': 2.242}, {'end': 662.759, 'text': "So can I say, whatever array is given to you, sorry, whatever d is given to you, doesn't matter.", 'start': 657.415, 'duration': 5.344}, {'end': 670.566, 'text': 'The number of rotations you have to do will always be d, modular, whatever is the size of the array.', 'start': 663.24, 'duration': 7.326}, {'end': 671.147, 'text': 'Can I say this?', 'start': 670.586, 'duration': 0.561}, {'end': 674.31, 'text': "if it's given like 20, doesn't matter.", 'start': 671.827, 'duration': 2.483}, {'end': 676.251, 'text': "i'll just have to do six rotations.", 'start': 674.31, 'duration': 1.941}, {'end': 683.919, 'text': 'because 20, modulus seven, will be six, which means you have to do seven two times and the remaining six.', 'start': 676.251, 'duration': 7.668}, {'end': 687.923, 'text': 'so you actually have to just do six rotations.', 'start': 683.919, 'duration': 4.004}], 'summary': 'Multiple of 7 rotations always brings back original array. number of rotations = d mod array size.', 'duration': 47.079, 'max_score': 640.844, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U640844.jpg'}, {'end': 751.49, 'src': 'embed', 'start': 727.933, 'weight': 1, 'content': [{'end': 737.059, 'text': 'whatever d is given to you, just do a modulo with n and that will be solving your problem and that will be solving your problem if d is very,', 'start': 727.933, 'duration': 9.126}, {'end': 737.92, 'text': 'very large.', 'start': 737.059, 'duration': 0.861}, {'end': 743.424, 'text': "so if in an interview this question comes up, the first approach that you'll be telling will be the brute force approach.", 'start': 737.92, 'duration': 5.504}, {'end': 746.826, 'text': 'now, what will be the brute force approach over here?', 'start': 744.224, 'duration': 2.602}, {'end': 748.687, 'text': "let's go back to the previous problem.", 'start': 746.826, 'duration': 1.861}, {'end': 751.49, 'text': 'in the previous problem, d was one element.', 'start': 748.687, 'duration': 2.803}], 'summary': 'To solve for d, use modulo with n; in interviews, start with brute force approach.', 'duration': 23.557, 'max_score': 727.933, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U727933.jpg'}], 'start': 445.737, 'title': 'Array rotation', 'summary': 'Discusses left rotating an array by a given number of places, exemplifying the case of left rotating an array by 2 places and explains the implications of rotating the array by different values of d. it also explains the logic behind array rotation, breaking down the number of rotations into multiples of the array size and using modulo to calculate the effective rotations.', 'chapters': [{'end': 561.863, 'start': 445.737, 'title': 'Left rotate array by d places', 'summary': 'Discusses the problem of left rotating an array by a given number of places, exemplifying the case of left rotating an array by 2 places and explaining the resultant array. it further explores the implications of rotating the array by different values of d.', 'duration': 116.126, 'highlights': ['It states you to left rotate the array, but this time by d places. Assuming for this given example array, we have d equal to 2.', "In that case, the answer would have been 4, 5, 6, 7, and then 1, 2, 3. So that's the answer for D equal to 3.", 'So if I do that, the resultant array will be three, four, five, six, seven and then one and two.']}, {'end': 748.687, 'start': 561.883, 'title': 'Array rotation logic', 'summary': 'Explains the logic behind array rotation, breaking down the number of rotations into multiples of the array size and using modulo to calculate the effective rotations. it emphasizes that for any given array size and number of rotations, the effective rotations can be calculated using the modulo operation.', 'duration': 186.804, 'highlights': ['Multiple of seven rotations will always bring you back to the original array, and the remaining is what you need to do.', 'The number of rotations needed will always be d modulo the size of the array, regardless of the value of d.', 'For any given d, just do a modulo with n to solve the problem, even if d is very large.']}], 'duration': 302.95, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U445737.jpg', 'highlights': ['The number of rotations needed will always be d modulo the size of the array, regardless of the value of d.', 'For any given d, just do a modulo with n to solve the problem, even if d is very large.', 'Multiple of seven rotations will always bring you back to the original array, and the remaining is what you need to do.', 'It states you to left rotate the array, but this time by d places. Assuming for this given example array, we have d equal to 2.', "In that case, the answer would have been 4, 5, 6, 7, and then 1, 2, 3. So that's the answer for D equal to 3.", 'So if I do that, the resultant array will be three, four, five, six, seven and then one and two.']}, {'end': 1357.741, 'segs': [{'end': 830.761, 'src': 'embed', 'start': 801.849, 'weight': 1, 'content': [{'end': 803.77, 'text': "Done So I've taken the first three.", 'start': 801.849, 'duration': 1.921}, {'end': 811.537, 'text': "I've taken the first three and I've put that into the temporary array, similar to what we did in the first problem.", 'start': 804.391, 'duration': 7.146}, {'end': 814.51, 'text': 'Now, what was the next step? Shifting.', 'start': 812.628, 'duration': 1.882}, {'end': 818.893, 'text': "So let's do the next job of shifting.", 'start': 814.93, 'duration': 3.963}, {'end': 827.901, 'text': "Now, when I say shifting, how will you shift? Let's write down the indexes and let's try to observe how do we shift.", 'start': 819.574, 'duration': 8.327}, {'end': 830.761, 'text': "So if I write down the indexes, it's like 0, 1, 2, 3, 4, 5, 6.", 'start': 828.422, 'duration': 2.339}], 'summary': 'Shifted first three elements into temporary array and analyzed index shifting.', 'duration': 28.912, 'max_score': 801.849, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U801849.jpg'}, {'end': 943.495, 'src': 'embed', 'start': 915.074, 'weight': 3, 'content': [{'end': 918.437, 'text': 'so once You have performed this shifting.', 'start': 915.074, 'duration': 3.363}, {'end': 920.538, 'text': "How will the array look like? Let's write.", 'start': 919.177, 'duration': 1.361}, {'end': 926.843, 'text': 'Once you perform this shifting, how will the array look like? It will look like 4 is here, 5 is here, 6 is here, 7 is here.', 'start': 921.019, 'duration': 5.824}, {'end': 931.787, 'text': 'Now you still have 3 places where 5, 6, 7 is there.', 'start': 926.883, 'duration': 4.904}, {'end': 935.851, 'text': 'And what do you need to put it? Like what do you need to put there? Very simple.', 'start': 932.228, 'duration': 3.623}, {'end': 938.312, 'text': 'You have to take this temporary.', 'start': 936.431, 'duration': 1.881}, {'end': 940.754, 'text': 'And you have to put the temporary one by one here.', 'start': 938.973, 'duration': 1.781}, {'end': 943.495, 'text': 'Which is like 1, 2, 3.', 'start': 941.035, 'duration': 2.46}], 'summary': 'Shifting the array will result in 4, 5, 6, 7 at new positions, and 1, 2, 3 at the end.', 'duration': 28.421, 'max_score': 915.074, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U915074.jpg'}, {'end': 990.54, 'src': 'embed', 'start': 960.785, 'weight': 0, 'content': [{'end': 971.133, 'text': 'So can I say if we are shifting by three places, it means, if the size of the array is seven, three places before it,', 'start': 960.785, 'duration': 10.348}, {'end': 977.955, 'text': 'because the last three places will only be occupied if we are shifting the array by three places.', 'start': 971.133, 'duration': 6.822}, {'end': 980.436, 'text': 'Only the last three places will be occupied.', 'start': 978.355, 'duration': 2.081}, {'end': 990.54, 'text': "So it'll be like, okay, seven minus three, which is basically n minus d, which is basically seven minus three, which is basically four.", 'start': 980.816, 'duration': 9.724}], 'summary': 'If shifting array by 3 places in a 7-size array, last 3 places will be occupied, resulting in 4 remaining positions.', 'duration': 29.755, 'max_score': 960.785, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U960785.jpg'}, {'end': 1013.089, 'src': 'heatmap', 'start': 960.785, 'weight': 0.703, 'content': [{'end': 971.133, 'text': 'So can I say if we are shifting by three places, it means, if the size of the array is seven, three places before it,', 'start': 960.785, 'duration': 10.348}, {'end': 977.955, 'text': 'because the last three places will only be occupied if we are shifting the array by three places.', 'start': 971.133, 'duration': 6.822}, {'end': 980.436, 'text': 'Only the last three places will be occupied.', 'start': 978.355, 'duration': 2.081}, {'end': 990.54, 'text': "So it'll be like, okay, seven minus three, which is basically n minus d, which is basically seven minus three, which is basically four.", 'start': 980.816, 'duration': 9.724}, {'end': 991.96, 'text': "So we're starting at four.", 'start': 991.04, 'duration': 0.92}, {'end': 996.062, 'text': 'Can I say we will start putting at the fourth index? Can I? I can.', 'start': 992.461, 'duration': 3.601}, {'end': 1004.165, 'text': "so i'll start from, i'll start putting it from the fourth, like n, minus k, and i'll go on to the last.", 'start': 996.602, 'duration': 7.563}, {'end': 1007.507, 'text': 'quite simple, and what will you put in the array of five?', 'start': 1004.165, 'duration': 3.342}, {'end': 1008.727, 'text': 'what will we put?', 'start': 1007.507, 'duration': 1.22}, {'end': 1013.089, 'text': "we'll put first one, so we'll put something from the temporary.", 'start': 1008.727, 'duration': 4.362}], 'summary': 'Shifting array by 3 places with 7 elements, starts at index 4.', 'duration': 52.304, 'max_score': 960.785, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U960785.jpg'}, {'end': 1235.5, 'src': 'embed', 'start': 1210.604, 'weight': 2, 'content': [{'end': 1216.429, 'text': 'Then you can easily shift and then you can easily put back the temporary array.', 'start': 1210.604, 'duration': 5.825}, {'end': 1218.331, 'text': 'This is how you can easily do it.', 'start': 1216.649, 'duration': 1.682}, {'end': 1223.796, 'text': 'So for this root approach, I have written the pseudocode so that you can code in C++ or Java.', 'start': 1219.112, 'duration': 4.684}, {'end': 1225.857, 'text': 'but coming to a cleaner code.', 'start': 1224.196, 'duration': 1.661}, {'end': 1234.32, 'text': 'we just take the array as the input and then we take the d and then we call the left rotate function which rotates it and then we just kind of like print it.', 'start': 1225.857, 'duration': 8.463}, {'end': 1235.5, 'text': "so let's look at the function.", 'start': 1234.32, 'duration': 1.18}], 'summary': 'Demonstrates shifting and putting back a temporary array, and implementing a left rotate function in c++ or java.', 'duration': 24.896, 'max_score': 1210.604, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U1210604.jpg'}, {'end': 1296.4, 'src': 'heatmap', 'start': 1143.376, 'weight': 5, 'content': [{'end': 1145.296, 'text': 'Take a pen and paper and try to do it yourself.', 'start': 1143.376, 'duration': 1.92}, {'end': 1146.457, 'text': "I'll repeat again.", 'start': 1145.817, 'duration': 0.64}, {'end': 1149.838, 'text': 'The base index here is n minus d.', 'start': 1147.097, 'duration': 2.741}, {'end': 1152.279, 'text': 'Then the next index will definitely be n minus d plus 1.', 'start': 1149.838, 'duration': 2.441}, {'end': 1154.66, 'text': 'The next will be n minus d plus 2.', 'start': 1152.279, 'duration': 2.381}, {'end': 1157.062, 'text': "right and we're taking from zero one two.", 'start': 1154.66, 'duration': 2.402}, {'end': 1161.605, 'text': 'so this is like zero, this is like one and this is like two.', 'start': 1157.062, 'duration': 4.543}, {'end': 1166.608, 'text': "that's why, wherever you are currently at, just subtract the base index.", 'start': 1161.605, 'duration': 5.003}, {'end': 1171.792, 'text': "if you subtract first, you'll get zero, then you'll get one, then you'll get two, which apparently means this.", 'start': 1166.608, 'duration': 5.184}, {'end': 1174.313, 'text': "so you'll automatically take the temporary.", 'start': 1171.792, 'duration': 2.521}, {'end': 1177.195, 'text': 'so this is how you can easily put it back.', 'start': 1174.313, 'duration': 2.882}, {'end': 1178.736, 'text': 'got it so quite simple.', 'start': 1177.195, 'duration': 1.541}, {'end': 1181.098, 'text': 'first i stored everything from the temporary again.', 'start': 1178.736, 'duration': 2.362}, {'end': 1186.021, 'text': 'to store everything for the temporary, you just need to loop from 0 to d.', 'start': 1181.098, 'duration': 4.923}, {'end': 1192.948, 'text': "So it's like looping from i equal to 0, i less than d, and i plus plus.", 'start': 1186.021, 'duration': 6.927}, {'end': 1198.573, 'text': 'And in the list, you can probably take a vector or a list in Java.', 'start': 1193.388, 'duration': 5.185}, {'end': 1199.734, 'text': 'Push back.', 'start': 1199.173, 'duration': 0.561}, {'end': 1203.537, 'text': 'In Java, it will be list.add array of i.', 'start': 1199.954, 'duration': 3.583}, {'end': 1203.818, 'text': "That's it.", 'start': 1203.537, 'duration': 0.281}, {'end': 1206.2, 'text': 'So this is the putting into the temporary.', 'start': 1204.238, 'duration': 1.962}, {'end': 1206.981, 'text': 'This is the step one.', 'start': 1206.22, 'duration': 0.761}, {'end': 1210.083, 'text': 'So this is how you can put everything over there.', 'start': 1207.681, 'duration': 2.402}, {'end': 1216.429, 'text': 'Then you can easily shift and then you can easily put back the temporary array.', 'start': 1210.604, 'duration': 5.825}, {'end': 1218.331, 'text': 'This is how you can easily do it.', 'start': 1216.649, 'duration': 1.682}, {'end': 1223.796, 'text': 'So for this root approach, I have written the pseudocode so that you can code in C++ or Java.', 'start': 1219.112, 'duration': 4.684}, {'end': 1225.857, 'text': 'but coming to a cleaner code.', 'start': 1224.196, 'duration': 1.661}, {'end': 1234.32, 'text': 'we just take the array as the input and then we take the d and then we call the left rotate function which rotates it and then we just kind of like print it.', 'start': 1225.857, 'duration': 8.463}, {'end': 1235.5, 'text': "so let's look at the function.", 'start': 1234.32, 'duration': 1.18}, {'end': 1245.984, 'text': 'so it takes an array, it takes the size of the array, takes t and the first step we make sure is we just reduce the d to something lesser than n,', 'start': 1235.5, 'duration': 10.484}, {'end': 1255.09, 'text': 'because we know on all the multiples of n it will come back to its orational array and then we store everything into temporary,', 'start': 1245.984, 'duration': 9.106}, {'end': 1261.115, 'text': 'then we shift it and after that we place back temporary into array.', 'start': 1255.09, 'duration': 6.025}, {'end': 1261.795, 'text': 'quite simple.', 'start': 1261.115, 'duration': 0.68}, {'end': 1265.778, 'text': 'so that was the cleaner code and the problem link will be in the description.', 'start': 1261.795, 'duration': 3.983}, {'end': 1268, 'text': 'so what will be the time complexity?', 'start': 1265.778, 'duration': 2.222}, {'end': 1272.544, 'text': 'so can i say the time complexity will be in order to do the step one.', 'start': 1268, 'duration': 4.544}, {'end': 1273.765, 'text': 'this is taking up.', 'start': 1272.544, 'duration': 1.221}, {'end': 1279.712, 'text': 'b go off d, Because we are looping through the first D elements.', 'start': 1273.765, 'duration': 5.947}, {'end': 1288.896, 'text': "Next, can I say, in order to transfer, like shift everything, that's going to take big O of N minus D.", 'start': 1280.272, 'duration': 8.624}, {'end': 1296.4, 'text': 'Because those many elements are what you will be transferring or shifting to the front, so N minus D.', 'start': 1288.896, 'duration': 7.504}], 'summary': 'The process involves shifting and storing elements in an array with time complexity of o(d) and o(n-d).', 'duration': 153.024, 'max_score': 1143.376, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U1143376.jpg'}, {'end': 1346.293, 'src': 'embed', 'start': 1317.605, 'weight': 6, 'content': [{'end': 1320.009, 'text': 'What is the extra space used? Extra.', 'start': 1317.605, 'duration': 2.404}, {'end': 1323.453, 'text': 'The extra space used will be Beko of D.', 'start': 1320.449, 'duration': 3.004}, {'end': 1327.439, 'text': "Why? Because you're using a temporary array to store the extra elements.", 'start': 1323.453, 'duration': 3.986}, {'end': 1333.547, 'text': 'Now, this is where the interviewer will tell you, okay, fine enough, but I want to get rid of this extra space.', 'start': 1327.819, 'duration': 5.728}, {'end': 1335.889, 'text': 'Can you just do it? and we go for an extra space.', 'start': 1333.627, 'duration': 2.262}, {'end': 1341.531, 'text': "That's when you say, okay, maybe I'll try to optimize this into an optimal solution.", 'start': 1336.449, 'duration': 5.082}, {'end': 1346.293, 'text': "For this, a better might not exist, so I'll not discuss it.", 'start': 1341.711, 'duration': 4.582}], 'summary': 'Using beko of d to store extra space for elements, aiming to optimize into an optimal solution.', 'duration': 28.688, 'max_score': 1317.605, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U1317605.jpg'}], 'start': 748.687, 'title': 'Array rotation and shifting', 'summary': 'Covers an algorithm for rotating arrays by a specified number of places, providing examples of rotating by 1, 2, and 3 places, as well as discussing shifting and rotating arrays, including step-by-step approach, pseudocode for implementation, cleaner code, time complexity, and extra space usage.', 'chapters': [{'end': 960.245, 'start': 748.687, 'title': 'Array rotation algorithm', 'summary': 'Discusses an algorithm for rotating an array by a specified number of places, demonstrating the process with examples of rotating by 1, 2, and 3 places and explaining the shifting and final array after the rotation.', 'duration': 211.558, 'highlights': ['The process of rotating an array by a specified number of places is demonstrated with examples of rotating by 1, 2, and 3 places, showcasing the shifting and final array after each rotation.', 'The algorithm involves storing a specified number of elements from the beginning of the array, shifting the remaining elements, and then putting the stored elements back, illustrating the process with quantifiable examples.', 'The shifting process is detailed, explaining the movement of elements to their new positions after the specified rotation, providing a clear understanding of how the shifting occurs within the array.']}, {'end': 1357.741, 'start': 960.785, 'title': 'Array shifting and rotating', 'summary': 'Covers the process of shifting and rotating arrays, demonstrating a step-by-step approach, pseudocode for implementation, and a cleaner code for the same, while also discussing time complexity and extra space usage, providing a comprehensive understanding of the topic.', 'duration': 396.956, 'highlights': ['The process of shifting and rotating arrays is explained, involving pseudocode and cleaner code for implementation, along with discussions on time complexity and extra space usage.', 'The pseudocode and implementation of shifting and rotating arrays are detailed, including the step-by-step process and a cleaner code.', 'The time complexity of the shifting and rotating process is analyzed, presenting a detailed breakdown of the steps involved.', 'The extra space usage in the shifting and rotating process is discussed, highlighting the use of a temporary array and considering the optimization into an optimal solution.']}], 'duration': 609.054, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U748687.jpg', 'highlights': ['The process of rotating an array by a specified number of places is demonstrated with examples of rotating by 1, 2, and 3 places, showcasing the shifting and final array after each rotation.', 'The algorithm involves storing a specified number of elements from the beginning of the array, shifting the remaining elements, and then putting the stored elements back, illustrating the process with quantifiable examples.', 'The process of shifting and rotating arrays is explained, involving pseudocode and cleaner code for implementation, along with discussions on time complexity and extra space usage.', 'The shifting process is detailed, explaining the movement of elements to their new positions after the specified rotation, providing a clear understanding of how the shifting occurs within the array.', 'The pseudocode and implementation of shifting and rotating arrays are detailed, including the step-by-step process and a cleaner code.', 'The time complexity of the shifting and rotating process is analyzed, presenting a detailed breakdown of the steps involved.', 'The extra space usage in the shifting and rotating process is discussed, highlighting the use of a temporary array and considering the optimization into an optimal solution.']}, {'end': 1997.973, 'segs': [{'end': 1469.248, 'src': 'heatmap', 'start': 1404.213, 'weight': 0, 'content': [{'end': 1410.296, 'text': 'post to reversal one is the first d, the next is the n minus d elements.', 'start': 1404.213, 'duration': 6.083}, {'end': 1415.132, 'text': 'after this, if you have to get this final array, What do you need to do?', 'start': 1410.296, 'duration': 4.836}, {'end': 1415.892, 'text': 'Reverse it again.', 'start': 1415.172, 'duration': 0.72}, {'end': 1419.734, 'text': 'So if you reverse it, what will happen? This 4 will come first.', 'start': 1415.912, 'duration': 3.822}, {'end': 1420.955, 'text': 'This 5 will come here.', 'start': 1420.074, 'duration': 0.881}, {'end': 1421.995, 'text': 'This 6 will come here.', 'start': 1420.975, 'duration': 1.02}, {'end': 1422.936, 'text': 'This 7 will come here.', 'start': 1422.035, 'duration': 0.901}, {'end': 1424.176, 'text': 'This 1 will come here.', 'start': 1423.296, 'duration': 0.88}, {'end': 1425.057, 'text': 'This 2 will come here.', 'start': 1424.216, 'duration': 0.841}, {'end': 1426.818, 'text': 'And this 3 will come here.', 'start': 1425.377, 'duration': 1.441}, {'end': 1427.538, 'text': 'Done and dusted.', 'start': 1426.838, 'duration': 0.7}, {'end': 1429.799, 'text': 'Yes This was super easy.', 'start': 1428.159, 'duration': 1.64}, {'end': 1432.161, 'text': 'So I will say reverse.', 'start': 1430.2, 'duration': 1.961}, {'end': 1436.863, 'text': 'First array to array plus d.', 'start': 1434.342, 'duration': 2.521}, {'end': 1437.724, 'text': 'Then I will say reverse.', 'start': 1436.863, 'duration': 0.861}, {'end': 1442.751, 'text': 'from array plus D to array plus N, which is the last one.', 'start': 1438.908, 'duration': 3.843}, {'end': 1447.474, 'text': "And then I'll say reverse the entire array, which is array to array plus N.", 'start': 1443.171, 'duration': 4.303}, {'end': 1455.299, 'text': 'So if I perform this three reversals, if I perform this three reversals, I will actually get the resultant array.', 'start': 1447.474, 'duration': 7.825}, {'end': 1460.203, 'text': "I don't have to do, like I don't have to take a temporary, do shiftings, and then copy pasting back again.", 'start': 1455.319, 'duration': 4.884}, {'end': 1461.724, 'text': 'Just three reversals.', 'start': 1460.703, 'duration': 1.021}, {'end': 1466.207, 'text': 'First for the D elements, then from D to N, and then the entire array.', 'start': 1462.184, 'duration': 4.023}, {'end': 1469.248, 'text': 'And if I do this, i should be done.', 'start': 1466.487, 'duration': 2.761}], 'summary': 'Perform 3 reversals to obtain resultant array, avoiding temporary shifts and copy-pasting.', 'duration': 65.035, 'max_score': 1404.213, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U1404213.jpg'}, {'end': 1515.306, 'src': 'embed', 'start': 1487.752, 'weight': 1, 'content': [{'end': 1491.453, 'text': 'so d and d will strike out and the complexity will be 2n.', 'start': 1487.752, 'duration': 3.701}, {'end': 1495.534, 'text': 'so the time complexity slightly increased from the previous one.', 'start': 1491.453, 'duration': 4.081}, {'end': 1497.775, 'text': 'but but the space complexity.', 'start': 1495.534, 'duration': 2.241}, {'end': 1500.176, 'text': 'we are not using any extra space.', 'start': 1497.775, 'duration': 2.401}, {'end': 1501.097, 'text': 'very important.', 'start': 1500.176, 'duration': 0.921}, {'end': 1502.978, 'text': "we're not using any extra space.", 'start': 1501.097, 'duration': 1.881}, {'end': 1506.04, 'text': 'yes, we are using the array that you can tell to the interview.', 'start': 1502.978, 'duration': 3.062}, {'end': 1508.882, 'text': 'but we are not using anything extra.', 'start': 1506.04, 'duration': 2.842}, {'end': 1510.183, 'text': "we're using the given array.", 'start': 1508.882, 'duration': 1.301}, {'end': 1512.724, 'text': "okay. so that's where the space complexity over here will be.", 'start': 1510.183, 'duration': 2.541}, {'end': 1515.306, 'text': 'pico of one got it.', 'start': 1512.724, 'duration': 2.582}], 'summary': 'Algorithm has time complexity of 2n, with no extra space used.', 'duration': 27.554, 'max_score': 1487.752, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U1487752.jpg'}, {'end': 1585.347, 'src': 'heatmap', 'start': 1537.655, 'weight': 1, 'content': [{'end': 1546.57, 'text': 'Then I can say again reverse array plus, sorry, plus zero, which means from zero the next to the last index.', 'start': 1537.655, 'duration': 8.915}, {'end': 1552.453, 'text': 'if we do this three steps, it will be done and i now i can quickly run this and see if it is running.', 'start': 1546.57, 'duration': 5.883}, {'end': 1554.215, 'text': "yes, and now you'll submit this.", 'start': 1552.453, 'duration': 1.762}, {'end': 1554.915, 'text': 'i should be submitted.', 'start': 1554.215, 'duration': 0.7}, {'end': 1561.357, 'text': 'so in case your programming language does not have a reverse function, you can always write something like this,', 'start': 1554.915, 'duration': 6.442}, {'end': 1569.04, 'text': 'which is a manual function where you take the starting index and the ending index, which means you want to reverse from this index to this index.', 'start': 1561.357, 'duration': 7.683}, {'end': 1570.32, 'text': 'and this is quite simple.', 'start': 1569.04, 'duration': 1.28}, {'end': 1571.18, 'text': 'you can go through this.', 'start': 1570.32, 'duration': 0.86}, {'end': 1577.602, 'text': "it's very, very simple and this will also work like if you write a manual function, just because in c plus plus there is an stl.", 'start': 1571.18, 'duration': 6.422}, {'end': 1580.183, 'text': "that's why i did not write an extra function.", 'start': 1577.602, 'duration': 2.581}, {'end': 1585.347, 'text': 'but in an interview the interviewer might ask you to write an additional function without using the stl.', 'start': 1580.183, 'duration': 5.164}], 'summary': 'Manually reverse array using starting and ending index if programming language lacks reverse function.', 'duration': 47.692, 'max_score': 1537.655, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U1537655.jpg'}, {'end': 1673.797, 'src': 'embed', 'start': 1645.819, 'weight': 3, 'content': [{'end': 1649.101, 'text': 'now your task is to move all the zeros to the end of the array.', 'start': 1645.819, 'duration': 3.282}, {'end': 1655.386, 'text': 'so first there will be one, then there will be two, then there will be three, then there will be two, then there will be four,', 'start': 1649.101, 'duration': 6.285}, {'end': 1657.688, 'text': 'then there will be five, then there will be one.', 'start': 1655.386, 'duration': 2.302}, {'end': 1662.992, 'text': 'so, basically, what you do is you take one, two, three, two, four, five, one.', 'start': 1657.688, 'duration': 5.304}, {'end': 1668.875, 'text': 'so i took all the non-zero numbers and i put them into the front of the array.', 'start': 1662.992, 'duration': 5.883}, {'end': 1671.876, 'text': "once i've done that, what are the remaining elements?", 'start': 1668.875, 'duration': 3.001}, {'end': 1673.797, 'text': 'there are zeros and there are three zeros.', 'start': 1671.876, 'duration': 1.921}], 'summary': 'Move all zeros to end, leaving 3 zeros.', 'duration': 27.978, 'max_score': 1645.819, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U1645819.jpg'}, {'end': 1714.17, 'src': 'embed', 'start': 1686.923, 'weight': 4, 'content': [{'end': 1691.825, 'text': 'you should definitely start with the brute force solution and then maybe come up with a better solution, if there is one,', 'start': 1686.923, 'duration': 4.902}, {'end': 1693.346, 'text': 'and then go to the optimal one.', 'start': 1691.825, 'duration': 1.521}, {'end': 1695.626, 'text': 'so what is the brute force solution?', 'start': 1693.826, 'duration': 1.8}, {'end': 1703.128, 'text': 'if you look at the problem, it states all the non-zero numbers at the front like all the non-zero numbers at the front.', 'start': 1695.626, 'duration': 7.502}, {'end': 1708.989, 'text': "so my mind kind of says that okay, let's pick up all the non-zero numbers and store it somewhere.", 'start': 1703.128, 'duration': 5.861}, {'end': 1711.529, 'text': "so what i'll do is i'll start iterating in the array.", 'start': 1708.989, 'duration': 2.54}, {'end': 1714.17, 'text': "so i'll start from the first index and i'll say it's a non-zero.", 'start': 1711.529, 'duration': 2.641}], 'summary': 'Start with brute force solution, pick non-zero numbers, iterate array.', 'duration': 27.247, 'max_score': 1686.923, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U1686923.jpg'}], 'start': 1358.181, 'title': 'Array rotation and moving zeros in arrays', 'summary': 'Explains array rotation using three reversals with time complexity of 2n and space complexity of o(1), also discusses left and right rotation, moving zeros to the end, providing a brute force solution, and analyzing time complexity and extra space usage.', 'chapters': [{'end': 1585.347, 'start': 1358.181, 'title': 'Array rotation algorithm', 'summary': 'Explains a method for rotating an array by three places using three reversals, with time complexity of 2n and space complexity of pico of one.', 'duration': 227.166, 'highlights': ['The method for rotating an array involves three reversals - first for the D elements, then from D to N, and then the entire array, resulting in a time complexity of 2n and space complexity of pico of one.', 'The space complexity of the array rotation algorithm is pico of one, as it does not require any additional space other than the given array.', 'The array rotation algorithm has a time complexity of 2n, which is slightly increased from the previous complexity, but it does not require any extra space.']}, {'end': 1997.973, 'start': 1585.347, 'title': 'Rotate and move zeros in array', 'summary': 'Discusses left and right rotation of an array and moving zeros to the end, providing a brute force solution and analyzing its time complexity and extra space usage.', 'duration': 412.626, 'highlights': ['The chapter discusses left and right rotation of an array and moving zeros to the end', 'Providing a brute force solution and analyzing its time complexity and extra space usage']}], 'duration': 639.792, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U1358181.jpg', 'highlights': ['The method for rotating an array involves three reversals with time complexity of 2n and space complexity of o(1)', 'The space complexity of the array rotation algorithm is o(1), as it does not require any additional space', 'The array rotation algorithm has a time complexity of 2n and does not require any extra space', 'The chapter discusses left and right rotation of an array and moving zeros to the end', 'Providing a brute force solution and analyzing its time complexity and extra space usage']}, {'end': 2569.889, 'segs': [{'end': 2024.491, 'src': 'embed', 'start': 1999.054, 'weight': 1, 'content': [{'end': 2004.057, 'text': 'So this will be the time complexity and space complexity for the brute force solution.', 'start': 1999.054, 'duration': 5.003}, {'end': 2009.201, 'text': 'So in case you want to code the brute force solution and submit it, the problem link will be in the description.', 'start': 2004.818, 'duration': 4.383}, {'end': 2013.424, 'text': "There is a reason why I'm writing the pseudocode so that you can code it in any of the languages.", 'start': 2009.541, 'duration': 3.883}, {'end': 2017.406, 'text': 'But still, if you want the Java and the Python codes, the link will be in the description.', 'start': 2013.784, 'duration': 3.622}, {'end': 2019.408, 'text': 'You can go to the notes and you can check them out.', 'start': 2017.446, 'duration': 1.962}, {'end': 2021.269, 'text': 'So the brute force solution is done.', 'start': 2019.848, 'duration': 1.421}, {'end': 2024.491, 'text': "It's time to move to the better solution, but there is no better solution.", 'start': 2021.709, 'duration': 2.782}], 'summary': 'Explanation of time and space complexity for brute force solution. links provided for java and python codes.', 'duration': 25.437, 'max_score': 1999.054, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U1999054.jpg'}, {'end': 2159.768, 'src': 'heatmap', 'start': 2059.826, 'weight': 2, 'content': [{'end': 2061.849, 'text': 'We will be trying to move the elements.', 'start': 2059.826, 'duration': 2.023}, {'end': 2065.373, 'text': "And in order to do that, we're already iterating in the array.", 'start': 2062.289, 'duration': 3.084}, {'end': 2068.516, 'text': 'Remember this, we are already iterating in the array.', 'start': 2065.853, 'duration': 2.663}, {'end': 2074.101, 'text': "So what we will do is, we'll try to use a two pointer approach to move it.", 'start': 2069.056, 'duration': 5.045}, {'end': 2082.467, 'text': 'Something similar to what we did in this particular problem where we did remove the duplicates from the sorted array.', 'start': 2074.581, 'duration': 7.886}, {'end': 2083.688, 'text': 'Something similar.', 'start': 2082.827, 'duration': 0.861}, {'end': 2089.453, 'text': "Now what I will say is, okay, hey, where's the first zero? And I'll say, here is my first zero.", 'start': 2084.007, 'duration': 5.446}, {'end': 2091.214, 'text': 'And this will be pointed by j.', 'start': 2089.993, 'duration': 1.221}, {'end': 2096.665, 'text': 'Which is the right next index after 0.', 'start': 2092.735, 'duration': 3.93}, {'end': 2097.206, 'text': 'Which is this.', 'start': 2096.665, 'duration': 0.541}, {'end': 2098.77, 'text': "I'll point it over here.", 'start': 2097.988, 'duration': 0.782}, {'end': 2100.493, 'text': 'Now what I say is.', 'start': 2099.591, 'duration': 0.902}, {'end': 2101.295, 'text': 'Hey listen.', 'start': 2100.914, 'duration': 0.381}, {'end': 2108.035, 'text': "I start from here and I check, are you a non-zero number? He says, yes, I'm a non-zero number.", 'start': 2102.611, 'duration': 5.424}, {'end': 2109.996, 'text': 'Okay, we have a zero here.', 'start': 2108.635, 'duration': 1.361}, {'end': 2111.837, 'text': "Let's swap it.", 'start': 2110.536, 'duration': 1.301}, {'end': 2113.058, 'text': "So I'll do a swap.", 'start': 2112.438, 'duration': 0.62}, {'end': 2116.78, 'text': 'So the two will go here and the zero will come here.', 'start': 2113.738, 'duration': 3.042}, {'end': 2119.863, 'text': 'The moment you have done a swap, you will say, okay, done.', 'start': 2117.221, 'duration': 2.642}, {'end': 2124.646, 'text': "Now I'll move to here and I'll also move the j to here.", 'start': 2120.743, 'duration': 3.903}, {'end': 2130.571, 'text': "So once I've moved, I'll just quickly erase this so that it's clearly, like it's clean.", 'start': 2125.768, 'duration': 4.803}, {'end': 2131.591, 'text': 'Done this.', 'start': 2131.291, 'duration': 0.3}, {'end': 2137.034, 'text': "Next, I'll say, hey, are you a non-zero number? He says, yes, I'm a non-zero number.", 'start': 2132.332, 'duration': 4.702}, {'end': 2139.435, 'text': "I'll say, okay, swap to the zero.", 'start': 2137.334, 'duration': 2.101}, {'end': 2141.597, 'text': "So I'll go across and again swap.", 'start': 2140.156, 'duration': 1.441}, {'end': 2143.738, 'text': 'So three goes here, zero comes here.', 'start': 2142.117, 'duration': 1.621}, {'end': 2149.321, 'text': 'And the moment you do that, I will move ahead and J will move to the next place.', 'start': 2144.078, 'duration': 5.243}, {'end': 2152.583, 'text': "And if you've done this, let's remove this so that it's again clean.", 'start': 2149.881, 'duration': 2.702}, {'end': 2157.846, 'text': "Next, are you a non-zero number? He says, yes, I'm a non-zero number.", 'start': 2153.623, 'duration': 4.223}, {'end': 2159.768, 'text': "I'm like, okay, swept.", 'start': 2158.487, 'duration': 1.281}], 'summary': 'Using a two-pointer approach to move non-zero numbers in the array and swapping with zeros.', 'duration': 99.942, 'max_score': 2059.826, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U2059826.jpg'}, {'end': 2336.761, 'src': 'heatmap', 'start': 2240.513, 'weight': 0.757, 'content': [{'end': 2243.334, 'text': 'and what we did was a single iteration.', 'start': 2240.513, 'duration': 2.821}, {'end': 2244.294, 'text': 'if you carefully observe,', 'start': 2243.334, 'duration': 0.96}, {'end': 2252.096, 'text': 'what we did was we started the iteration like we first figured out the zero and then we started the iteration and we went till the end.', 'start': 2244.294, 'duration': 7.802}, {'end': 2257.28, 'text': "so it's like a one iteration we did, which is much better than what we were doing previously.", 'start': 2252.096, 'duration': 5.184}, {'end': 2259.442, 'text': 'right, see the optimal solution.', 'start': 2257.28, 'duration': 2.162}, {'end': 2260.843, 'text': 'what is my step one?', 'start': 2259.442, 'duration': 1.401}, {'end': 2263.485, 'text': 'if i have to ask you, what is my step one?', 'start': 2260.843, 'duration': 2.642}, {'end': 2265.687, 'text': "it's finding the first zeroth element.", 'start': 2263.485, 'duration': 2.202}, {'end': 2270.212, 'text': 'so what you can do is you can probably say j is initially minus one, okay,', 'start': 2265.687, 'duration': 4.525}, {'end': 2277.758, 'text': 'and then you can start from zero and you can go on till i plus plus and you say hey, array of i, are you zero?', 'start': 2270.212, 'duration': 7.546}, {'end': 2281.68, 'text': "if you're zero, okay, fine j.", 'start': 2278.479, 'duration': 3.201}, {'end': 2284.702, 'text': 'store this index because this is zero and just go out.', 'start': 2281.68, 'duration': 3.022}, {'end': 2296.727, 'text': 'no need to go ahead, go out and this will make sure j is stored as the first like whatever the first zero is, if j is still minus one,', 'start': 2284.702, 'duration': 12.025}, {'end': 2298.588, 'text': 'it means there is nothing and you can just stop.', 'start': 2296.727, 'duration': 1.861}, {'end': 2300.529, 'text': 'you can just stop if j is still minus one.', 'start': 2298.588, 'duration': 1.941}, {'end': 2303.23, 'text': 'there is no zero and all unknown zero elements.', 'start': 2300.529, 'duration': 2.701}, {'end': 2305.511, 'text': 'so you can stop the moment you have j.', 'start': 2303.23, 'duration': 2.281}, {'end': 2306.171, 'text': "what's the next step?", 'start': 2305.511, 'duration': 0.66}, {'end': 2306.852, 'text': 'we did?', 'start': 2306.171, 'duration': 0.681}, {'end': 2312.521, 'text': 'we took a i right at the next object, and this is where we start out.', 'start': 2306.852, 'duration': 5.669}, {'end': 2316.665, 'text': "so i said, okay, i'll start from g plus one and i'll go until here.", 'start': 2312.521, 'duration': 4.144}, {'end': 2318.247, 'text': 'and what did we do?', 'start': 2316.665, 'duration': 1.582}, {'end': 2320.168, 'text': 'we said, hey, are you a non-zero?', 'start': 2318.247, 'duration': 1.921}, {'end': 2320.989, 'text': 'are you a non-zero?', 'start': 2320.168, 'duration': 0.821}, {'end': 2323.652, 'text': "he said, yes, i am, so i'll check.", 'start': 2320.989, 'duration': 2.663}, {'end': 2328.136, 'text': 'hey, if array of i are you a non-zero number?', 'start': 2323.652, 'duration': 4.484}, {'end': 2336.761, 'text': 'if you are a non-zero number, can you please swap yourself with array of i and array of j?', 'start': 2328.136, 'duration': 8.625}], 'summary': 'Implemented single iteration to find and swap zero and non-zero elements in array, improving efficiency.', 'duration': 96.248, 'max_score': 2240.513, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U2240513.jpg'}, {'end': 2270.212, 'src': 'embed', 'start': 2244.294, 'weight': 3, 'content': [{'end': 2252.096, 'text': 'what we did was we started the iteration like we first figured out the zero and then we started the iteration and we went till the end.', 'start': 2244.294, 'duration': 7.802}, {'end': 2257.28, 'text': "so it's like a one iteration we did, which is much better than what we were doing previously.", 'start': 2252.096, 'duration': 5.184}, {'end': 2259.442, 'text': 'right, see the optimal solution.', 'start': 2257.28, 'duration': 2.162}, {'end': 2260.843, 'text': 'what is my step one?', 'start': 2259.442, 'duration': 1.401}, {'end': 2263.485, 'text': 'if i have to ask you, what is my step one?', 'start': 2260.843, 'duration': 2.642}, {'end': 2265.687, 'text': "it's finding the first zeroth element.", 'start': 2263.485, 'duration': 2.202}, {'end': 2270.212, 'text': 'so what you can do is you can probably say j is initially minus one, okay,', 'start': 2265.687, 'duration': 4.525}], 'summary': 'Iterative process improved with one iteration, reaching the end, aiming for optimal solution.', 'duration': 25.918, 'max_score': 2244.294, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U2244294.jpg'}, {'end': 2488.885, 'src': 'embed', 'start': 2460.16, 'weight': 0, 'content': [{'end': 2461.821, 'text': 'It just involves iteration.', 'start': 2460.16, 'duration': 1.661}, {'end': 2465.583, 'text': 'If you understand iteration in an array, you should be able to solve linear search.', 'start': 2461.841, 'duration': 3.742}, {'end': 2469.426, 'text': "Now, what does linear search say? It says that you'll be given an array.", 'start': 2465.963, 'duration': 3.463}, {'end': 2474.11, 'text': 'array of numbers and you will also be given a separate number.', 'start': 2470.046, 'duration': 4.064}, {'end': 2482.118, 'text': 'you have to tell me which is the first occurrence, very important, which is the first occurrence of this number in an array.', 'start': 2474.11, 'duration': 8.008}, {'end': 2486.282, 'text': 'so if i have to check this is where the number occurs.', 'start': 2482.118, 'duration': 4.164}, {'end': 2487.824, 'text': 'what is the zero based indexing?', 'start': 2486.282, 'duration': 1.542}, {'end': 2488.885, 'text': 'again very important.', 'start': 2487.824, 'duration': 1.061}], 'summary': 'Linear search finds first occurrence of a number in an array using iteration.', 'duration': 28.725, 'max_score': 2460.16, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U2460160.jpg'}], 'start': 1999.054, 'title': 'Optimal solution and array rearrangement', 'summary': 'Discusses the two pointer approach for efficient solution with time complexity analysis and introduces optimal array rearrangement with linear search problem and its o(n) time complexity solution.', 'chapters': [{'end': 2083.688, 'start': 1999.054, 'title': 'Optimal solution with two pointer approach', 'summary': 'Discusses the time complexity and space complexity for the brute force solution, transitioning to the optimal solution using a two pointer approach to iterate through the array and move elements for a more efficient solution.', 'duration': 84.634, 'highlights': ['The chapter discusses the time complexity and space complexity for the brute force solution, emphasizing the transition to the optimal solution. It also mentions the availability of problem links and pseudocode for coding in different languages.', 'Introduces the concept of an optimal solution and the thought process behind it, emphasizing the use of a two pointer approach to efficiently move elements while iterating through the array.']}, {'end': 2569.889, 'start': 2084.007, 'title': 'Optimal array rearrangement', 'summary': 'Explains an optimal approach for rearranging an array where all non-zero elements are moved to the front and all zeros are moved to the end, achieved through a single iteration and a time complexity of o(n). it also introduces the linear search problem and its solution approach.', 'duration': 485.882, 'highlights': ['The chapter explains an optimal approach for rearranging an array where all non-zero elements are moved to the front and all zeros are moved to the end, achieved through a single iteration and a time complexity of O(n).', 'The approach involves finding the first zero element and then iterating through the array to swap non-zero elements with the zeros, effectively moving the non-zero elements to the front and zeros to the end.', 'The time complexity of the approach is calculated as O(x + (n - x)), where x is the index of the first zero element found in the array.', "Furthermore, the chapter introduces the linear search problem, which involves finding the first occurrence of a given number in an array and returning its index, or -1 if it doesn't exist."]}], 'duration': 570.835, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U1999054.jpg', 'highlights': ['The chapter introduces the linear search problem with a time complexity of O(n).', 'The chapter discusses the time complexity and space complexity for the brute force solution.', 'The chapter explains an optimal approach for rearranging an array with a time complexity of O(n).', 'The approach involves finding the first zero element and then iterating through the array to swap non-zero elements with the zeros.', 'The chapter emphasizes the use of a two pointer approach to efficiently move elements while iterating through the array.']}, {'end': 2998.289, 'segs': [{'end': 2611.426, 'src': 'embed', 'start': 2569.889, 'weight': 0, 'content': [{'end': 2573.991, 'text': 'and again, the Java and the Python code will be given in the notes so you can check them out as well.', 'start': 2569.889, 'duration': 4.102}, {'end': 2577.852, 'text': 'So, with this, the most easiest problem in the array playlist is done as well.', 'start': 2574.171, 'duration': 3.681}, {'end': 2584.154, 'text': "and now let's go to the next problem, which is finding the union and the intersection of two given sorted arrays.", 'start': 2577.852, 'duration': 6.302}, {'end': 2588.516, 'text': 'So what is the problem statement? Union of two sorted.', 'start': 2584.774, 'duration': 3.742}, {'end': 2594.638, 'text': 'Again, very, very important word because this will be helping us to determine the most optimal solution.', 'start': 2588.676, 'duration': 5.962}, {'end': 2597.659, 'text': 'So union of two sorted arrays.', 'start': 2595.138, 'duration': 2.521}, {'end': 2601.641, 'text': 'So this is array one, which is sorted in itself, might have duplicates.', 'start': 2598.159, 'duration': 3.482}, {'end': 2604.622, 'text': 'Array two sorted in itself again might have duplicates.', 'start': 2602.241, 'duration': 2.381}, {'end': 2607.763, 'text': 'So what you have to do is you have to give me an union array.', 'start': 2605.002, 'duration': 2.761}, {'end': 2609.324, 'text': 'What is the meaning of union?', 'start': 2608.203, 'duration': 1.121}, {'end': 2611.426, 'text': 'so what do you mean by union?', 'start': 2609.904, 'duration': 1.522}], 'summary': 'The transcript discusses solving the union and intersection of two sorted arrays.', 'duration': 41.537, 'max_score': 2569.889, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U2569889.jpg'}, {'end': 2692.98, 'src': 'embed', 'start': 2657.622, 'weight': 2, 'content': [{'end': 2658.763, 'text': "It's not here, but it's okay.", 'start': 2657.622, 'duration': 1.141}, {'end': 2660.284, 'text': 'You have to add both of them.', 'start': 2658.783, 'duration': 1.501}, {'end': 2661.284, 'text': 'You have to add both of them.', 'start': 2660.404, 'duration': 0.88}, {'end': 2662.965, 'text': 'And make sure there is no duplicates.', 'start': 2661.524, 'duration': 1.441}, {'end': 2667.507, 'text': 'So, this will be the answer for union of two sorted arrays.', 'start': 2663.385, 'duration': 4.122}, {'end': 2669.288, 'text': 'And this is what you have to return.', 'start': 2667.567, 'duration': 1.721}, {'end': 2672.39, 'text': 'So, So this problem comes up in an interview.', 'start': 2669.729, 'duration': 2.661}, {'end': 2676.112, 'text': "The first solution that you'll be telling the interviewer should be the brute force approach.", 'start': 2672.71, 'duration': 3.402}, {'end': 2680.794, 'text': "What will be the brute force approach? What are we doing? We're combining both of them.", 'start': 2676.632, 'duration': 4.162}, {'end': 2686.197, 'text': 'But we are making sure the unique elements are just there in the union array.', 'start': 2681.074, 'duration': 5.123}, {'end': 2692.98, 'text': 'So whenever we hear something like unique, something like a map, or like a set, comes to our head.', 'start': 2686.737, 'duration': 6.243}], 'summary': 'Interview problem: find union of two sorted arrays with unique elements using brute force approach.', 'duration': 35.358, 'max_score': 2657.622, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U2657622.jpg'}, {'end': 2904.138, 'src': 'heatmap', 'start': 2857.805, 'weight': 0.889, 'content': [{'end': 2865.212, 'text': 'maybe you can keep a pointer like i equal to zero and you can say union i plus plus equal to it.', 'start': 2857.805, 'duration': 7.407}, {'end': 2869.015, 'text': 'so first time goes to the first zeroth index into the second index.', 'start': 2865.212, 'duration': 3.803}, {'end': 2875.179, 'text': "if you're using something like a list or a vector, you can simply write union dot, add or push back.", 'start': 2869.015, 'duration': 6.164}, {'end': 2878.161, 'text': 'in that case it, and this will add it directly.', 'start': 2875.179, 'duration': 2.982}, {'end': 2880.163, 'text': "you don't have to maintain an index.", 'start': 2878.161, 'duration': 2.002}, {'end': 2883.625, 'text': 'so this is how the step two looks like now.', 'start': 2880.163, 'duration': 3.462}, {'end': 2888.349, 'text': 'if i have to discuss the time complexity of this particular brute force approach, what will it be?', 'start': 2883.625, 'duration': 4.724}, {'end': 2889.109, 'text': 'can i say the stakes?', 'start': 2888.349, 'duration': 0.76}, {'end': 2896.695, 'text': 'we go off n1, log n1, not N1, log N, where N is the size of the set.', 'start': 2889.109, 'duration': 7.586}, {'end': 2899.142, 'text': 'So N1 log N.', 'start': 2897.357, 'duration': 1.785}, {'end': 2904.138, 'text': 'And over here, can I say that this complexity will be n to log n.', 'start': 2900.154, 'duration': 3.984}], 'summary': 'Using brute force approach, time complexity is n1 log n, or n to log n.', 'duration': 46.333, 'max_score': 2857.805, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U2857805.jpg'}, {'end': 2979.372, 'src': 'embed', 'start': 2932.738, 'weight': 4, 'content': [{'end': 2937.259, 'text': 'and if all different go into the set, it will be n1 over here, n2 over here.', 'start': 2932.738, 'duration': 4.521}, {'end': 2940.82, 'text': 'so the total elements in the set will be n1 plus n2.', 'start': 2937.259, 'duration': 3.561}, {'end': 2949.662, 'text': 'if every element is unique, if every element is unique, so can i say the time complexity stands at for the first insertion n log n,', 'start': 2940.82, 'duration': 8.842}, {'end': 2950.902, 'text': 'for the second n2 log n.', 'start': 2949.662, 'duration': 1.24}, {'end': 2955.059, 'text': 'And then a big O of n1 plus n2 are the worst case.', 'start': 2951.696, 'duration': 3.363}, {'end': 2963.665, 'text': "And the space complexity is we're using an external set, which might end up taking n1 plus n2 are the worst case if all of them are unique.", 'start': 2955.479, 'duration': 8.186}, {'end': 2967.268, 'text': "And then we're using a union array in order to return the answer.", 'start': 2964.046, 'duration': 3.222}, {'end': 2970.21, 'text': 'Again, this is not used to solve the problem.', 'start': 2967.688, 'duration': 2.522}, {'end': 2972.132, 'text': 'This is used to return the answer.', 'start': 2970.551, 'duration': 1.581}, {'end': 2979.372, 'text': 'Please specifically mention that to the interviewer that this N1 plus N2 space is used to return the answer.', 'start': 2973.086, 'duration': 6.286}], 'summary': 'Time complexity: o(n1 log n) + o(n2 log n), space complexity: o(n1 + n2)', 'duration': 46.634, 'max_score': 2932.738, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U2932738.jpg'}], 'start': 2569.889, 'title': 'Union and intersection of sorted arrays', 'summary': "Covers finding the union and intersection of two given sorted arrays, emphasizing the importance of the 'union' concept, providing java and python code for reference, and discussing the time and space complexity of the union of two sorted arrays.", 'chapters': [{'end': 2611.426, 'start': 2569.889, 'title': 'Finding union and intersection of sorted arrays', 'summary': "Covers finding the union and intersection of two given sorted arrays, emphasizing the importance of the 'union' concept and providing java and python code in the notes for reference. additionally, it mentions completing the easiest problem in the array playlist.", 'duration': 41.537, 'highlights': ["The chapter emphasizes the importance of the 'union' concept for determining the most optimal solution, providing Java and Python code in the notes for reference.", 'It mentions completing the easiest problem in the array playlist as well.', 'The problem statement involves finding the union and intersection of two given sorted arrays, with the requirement to produce a union array.', 'The chapter explains the meaning of union in the context of the problem, with a focus on handling sorted arrays with possible duplicates.']}, {'end': 2998.289, 'start': 2611.426, 'title': 'Union of two sorted arrays', 'summary': 'Discusses the union of two sorted arrays, emphasizing the use of a set data structure to efficiently find unique elements and maintain sorted order, with a time complexity of o(n1 + n2) and space complexity of o(n1 + n2) in the worst case.', 'duration': 386.863, 'highlights': ['The chapter discusses the union of two sorted arrays, emphasizing the use of a set data structure to efficiently find unique elements and maintain sorted order.', 'The time complexity of the brute force approach is O(n1 + n2) in the worst case, where n1 and n2 are the sizes of the two arrays.', 'The space complexity of the brute force approach is O(n1 + n2) in the worst case, considering the use of an external set and a union array.']}], 'duration': 428.4, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U2569889.jpg', 'highlights': ["The chapter emphasizes the importance of the 'union' concept for determining the most optimal solution, providing Java and Python code in the notes for reference.", 'The chapter discusses the union of two sorted arrays, emphasizing the use of a set data structure to efficiently find unique elements and maintain sorted order.', 'The problem statement involves finding the union and intersection of two given sorted arrays, with the requirement to produce a union array.', 'The chapter explains the meaning of union in the context of the problem, with a focus on handling sorted arrays with possible duplicates.', 'The time complexity of the brute force approach is O(n1 + n2) in the worst case, where n1 and n2 are the sizes of the two arrays.', 'The space complexity of the brute force approach is O(n1 + n2) in the worst case, considering the use of an external set and a union array.', 'It mentions completing the easiest problem in the array playlist as well.']}, {'end': 3318.477, 'segs': [{'end': 3087.836, 'src': 'embed', 'start': 3056.613, 'weight': 2, 'content': [{'end': 3058.114, 'text': 'look at the union array.', 'start': 3056.613, 'duration': 1.501}, {'end': 3062.177, 'text': 'the first element of the union array will be the smallest one, will be the smallest one.', 'start': 3058.114, 'duration': 4.063}, {'end': 3066.1, 'text': 'so if i have to take the smallest one, who among it is the smaller one?', 'start': 3062.177, 'duration': 3.923}, {'end': 3067.221, 'text': 'obviously one.', 'start': 3066.1, 'duration': 1.121}, {'end': 3073.325, 'text': "so what i'll do is i'll take the one into the union array and i'll move the i pointer to the next index.", 'start': 3067.221, 'duration': 6.104}, {'end': 3075.367, 'text': "i'll move the i pointer to the next index.", 'start': 3073.325, 'duration': 2.042}, {'end': 3082.752, 'text': "now, if i have to again take something into the union array, i'll definitely take one, because it's still smaller than two.", 'start': 3075.367, 'duration': 7.385}, {'end': 3087.836, 'text': 'but I say wait, the last element I took into the union array was one.', 'start': 3082.752, 'duration': 5.084}], 'summary': 'The smallest element is one, added to the union array, and the pointer moves to the next index.', 'duration': 31.223, 'max_score': 3056.613, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U3056613.jpg'}, {'end': 3251.963, 'src': 'embed', 'start': 3197.929, 'weight': 0, 'content': [{'end': 3203.795, 'text': "you will iterate in the remaining portion of the other array and you will check if it's equivalent to back or not,", 'start': 3197.929, 'duration': 5.866}, {'end': 3206.318, 'text': 'and then you will keep on inserting into the union.', 'start': 3203.795, 'duration': 2.523}, {'end': 3212.424, 'text': "so once it's done, you will have your union array ready and this will be your answer.", 'start': 3206.318, 'duration': 6.106}, {'end': 3212.944, 'text': 'got it?', 'start': 3212.424, 'duration': 0.52}, {'end': 3213.825, 'text': "let's code the optimal.", 'start': 3212.944, 'duration': 0.881}, {'end': 3216.088, 'text': 'Again. the problem link will be in the description.', 'start': 3214.286, 'duration': 1.802}, {'end': 3224.961, 'text': "So we're given this function sorted array where we have to return a list and we're given a couple of arrays, right? So at first I'll do one thing.", 'start': 3216.489, 'duration': 8.472}, {'end': 3228.706, 'text': "I'll just figure out the size of the first array, which is something like this.", 'start': 3225.181, 'duration': 3.525}, {'end': 3231.846, 'text': "And I'll also figure out the size of the second array, which is something like this.", 'start': 3229.264, 'duration': 2.582}, {'end': 3238.011, 'text': "And now I know I'll have two pointers, i, which will be pointing to the first index of the first array, and j, which will be pointing.", 'start': 3232.407, 'duration': 5.604}, {'end': 3244.036, 'text': 'And then we will also have a list, which will be the answer, which is a union array.', 'start': 3238.372, 'duration': 5.664}, {'end': 3247.019, 'text': 'And then at the end of the day, we will be returning this particular list.', 'start': 3244.396, 'duration': 2.623}, {'end': 3248.8, 'text': 'This is something we do.', 'start': 3248.039, 'duration': 0.761}, {'end': 3251.963, 'text': "Now let's say we are comparing both.", 'start': 3249.541, 'duration': 2.422}], 'summary': 'Iterate through arrays, create union array, and return it.', 'duration': 54.034, 'max_score': 3197.929, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U3197929.jpg'}], 'start': 2998.309, 'title': 'Optimal approach for merging sorted arrays and finding union', 'summary': 'Covers the optimal approach for merging two sorted arrays using a two-pointer approach and demonstrates it with detailed examples, highlighting the importance of unique elements. it also discusses the algorithm for finding the union of two sorted arrays by iterating through the arrays and comparing elements, resulting in a final union array.', 'chapters': [{'end': 3197.929, 'start': 2998.309, 'title': 'Optimal approach for merging sorted arrays', 'summary': 'Explains the optimal approach for merging two sorted arrays using a two-pointer approach and demonstrates the process with detailed examples, emphasizing the importance of unique elements and iterating through the remaining portion of the array.', 'duration': 199.62, 'highlights': ['The optimal approach involves using a two-pointer approach to merge two sorted arrays, ensuring that unique elements are added to the union list, as demonstrated through detailed examples.', 'The process involves iterating through both arrays, comparing and adding the smallest element to the union list, with an emphasis on not adding duplicate elements.', 'The importance of iterating through the remaining portion of one array if the iteration on one of the arrays is over is emphasized, ensuring all elements are included in the union list.']}, {'end': 3318.477, 'start': 3197.929, 'title': 'Finding union of two sorted arrays', 'summary': 'Discusses the algorithm for finding the union of two sorted arrays by iterating through the arrays and comparing elements, resulting in a final union array, and returning it as the answer.', 'duration': 120.548, 'highlights': ['The algorithm involves iterating through the arrays, comparing elements, and inserting into the union array, resulting in the final union array as the answer.', 'The size of the first and second arrays is determined at the start of the function to facilitate the iteration process.', 'Two pointers, i and j, are used to iterate through the first and second arrays, and a list is maintained to store the union array, which is returned as the final result.']}], 'duration': 320.168, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U2998309.jpg', 'highlights': ['The optimal approach involves using a two-pointer approach to merge two sorted arrays, ensuring that unique elements are added to the union list, as demonstrated through detailed examples.', 'The algorithm involves iterating through the arrays, comparing elements, and inserting into the union array, resulting in the final union array as the answer.', 'The process involves iterating through both arrays, comparing and adding the smallest element to the union list, with an emphasis on not adding duplicate elements.', 'The importance of iterating through the remaining portion of one array if the iteration on one of the arrays is over is emphasized, ensuring all elements are included in the union list.', 'The size of the first and second arrays is determined at the start of the function to facilitate the iteration process.', 'Two pointers, i and j, are used to iterate through the first and second arrays, and a list is maintained to store the union array, which is returned as the final result.']}, {'end': 4387.619, 'segs': [{'end': 3364.97, 'src': 'embed', 'start': 3338.45, 'weight': 4, 'content': [{'end': 3342.133, 'text': "Then you always take the one if the union array is empty because it's the first time.", 'start': 3338.45, 'duration': 3.683}, {'end': 3353.761, 'text': "If it's the first time, which means union array.size is equal to zero, then you always, sorry, or, you always take it.", 'start': 3342.153, 'duration': 11.608}, {'end': 3356.604, 'text': "So if the size is zero, it means it's for the first time.", 'start': 3354.282, 'duration': 2.322}, {'end': 3358.085, 'text': 'You just take it.', 'start': 3356.624, 'duration': 1.461}, {'end': 3362.368, 'text': 'And similarly, you go to the else, which means the other element is the smaller.', 'start': 3358.785, 'duration': 3.583}, {'end': 3364.97, 'text': 'The other element in the B array is smaller.', 'start': 3362.788, 'duration': 2.182}], 'summary': 'If union array is empty, take the first element; else, the b array element is smaller.', 'duration': 26.52, 'max_score': 3338.45, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U3338450.jpg'}, {'end': 3476.083, 'src': 'heatmap', 'start': 3385.305, 'weight': 0.785, 'content': [{'end': 3388.127, 'text': 'And after this is completed, I will return.', 'start': 3385.305, 'duration': 2.822}, {'end': 3388.688, 'text': 'But wait.', 'start': 3388.267, 'duration': 0.421}, {'end': 3396.914, 'text': 'What if, while iterating this got exhausted, the first array got exhausted, so there must be someone left.', 'start': 3389.388, 'duration': 7.526}, {'end': 3402.178, 'text': 'if you remember our case, we completed the iteration and there were still two elements left.', 'start': 3396.914, 'duration': 5.264}, {'end': 3403.739, 'text': 'there were still two elements left.', 'start': 3402.178, 'duration': 1.561}, {'end': 3404.679, 'text': 'what do you that means?', 'start': 3403.739, 'duration': 0.94}, {'end': 3405.64, 'text': 'j would be somewhere here.', 'start': 3404.679, 'duration': 0.961}, {'end': 3408.902, 'text': 'so you need to iterate for this these remaining elements.', 'start': 3405.64, 'duration': 3.262}, {'end': 3417.268, 'text': "so write it so you say okay, listen, if the first was exhausted, j will still be there, and if j is still there, let's do the same thing.", 'start': 3408.902, 'duration': 8.366}, {'end': 3425.737, 'text': "I'll say hey, listen, I'll do the same thing, which means okay, fine, if you're not equivalent, go in and just keep on moving.", 'start': 3418.349, 'duration': 7.388}, {'end': 3427.959, 'text': 'and what if the second got exhausted?', 'start': 3425.737, 'duration': 2.222}, {'end': 3429, 'text': 'so I will still be there.', 'start': 3427.959, 'duration': 1.041}, {'end': 3432.744, 'text': 'there is someone still in the first and there is someone still in the first.', 'start': 3429, 'duration': 3.744}, {'end': 3436.128, 'text': 'you simply take, take it without any thinking.', 'start': 3432.744, 'duration': 3.384}, {'end': 3440.852, 'text': "yes, without any thinking, you simply take it, And once you've done this, you can return it.", 'start': 3436.128, 'duration': 4.724}, {'end': 3445.035, 'text': 'So this is the remaining arrays that you just iterate through.', 'start': 3441.332, 'duration': 3.703}, {'end': 3448.878, 'text': "Once you've done this, you can go ahead and really let's submit.", 'start': 3445.456, 'duration': 3.422}, {'end': 3452.181, 'text': "I'm sure that I write error-free code.", 'start': 3449.099, 'duration': 3.082}, {'end': 3453.082, 'text': 'Oh yeah, I do.', 'start': 3452.321, 'duration': 0.761}, {'end': 3459.467, 'text': "So at one go, I've submitted this code and this is exactly how it will look like.", 'start': 3453.462, 'duration': 6.005}, {'end': 3469.096, 'text': 'Now, if I have to ask you the time complexity of this particular code, what will be the time complexity of this particular code?', 'start': 3459.847, 'duration': 9.249}, {'end': 3470.517, 'text': 'Can I see?', 'start': 3470.057, 'duration': 0.46}, {'end': 3476.083, 'text': "I'm iterating in some way throughout this entire somewhere.", 'start': 3471.879, 'duration': 4.204}], 'summary': 'Iterating through remaining elements and ensuring all are processed; ensuring error-free code submission.', 'duration': 90.778, 'max_score': 3385.305, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U3385305.jpg'}, {'end': 3567.843, 'src': 'heatmap', 'start': 3516.642, 'weight': 1, 'content': [{'end': 3518.904, 'text': 'So n1 plus n2 is the time complexity.', 'start': 3516.642, 'duration': 2.262}, {'end': 3524.348, 'text': "And space, you can say, I'm just using n1 plus n2 at the worst case if all the elements are unique.", 'start': 3519.244, 'duration': 5.104}, {'end': 3527.471, 'text': 'And that is for returning the answer, not for solving.', 'start': 3524.709, 'duration': 2.762}, {'end': 3530.352, 'text': 'not in my algorithm, using that to return.', 'start': 3527.791, 'duration': 2.561}, {'end': 3538.397, 'text': "tell that specifically to the interviewer and that's how your optimal solution will look like in order to union two sorted arrays.", 'start': 3530.352, 'duration': 8.045}, {'end': 3541.559, 'text': "so what i can say is i'll go back to the sheet.", 'start': 3538.397, 'duration': 3.162}, {'end': 3542.639, 'text': 'the union is done.', 'start': 3541.559, 'duration': 1.08}, {'end': 3546.401, 'text': "now it's time to understand the intersection of two sorted arrays.", 'start': 3542.639, 'duration': 3.762}, {'end': 3548.442, 'text': 'so what does the problem statement state?', 'start': 3546.401, 'duration': 2.041}, {'end': 3550.643, 'text': 'intersection of two sorted arrays.', 'start': 3548.442, 'duration': 2.201}, {'end': 3557.511, 'text': 'again, the term sorted is very important if you want to go for the optimal solution.', 'start': 3550.643, 'duration': 6.868}, {'end': 3558.552, 'text': 'so keep that in mind.', 'start': 3557.511, 'duration': 1.041}, {'end': 3560.955, 'text': 'okay, what do you mean by intersection?', 'start': 3558.552, 'duration': 2.403}, {'end': 3562.777, 'text': 'the element that is present in both.', 'start': 3560.955, 'duration': 1.822}, {'end': 3567.843, 'text': 'i remember this present in both, present in both.', 'start': 3562.777, 'duration': 5.066}], 'summary': 'Time complexity is n1 plus n2. optimal solution for union and intersection of sorted arrays.', 'duration': 66.271, 'max_score': 3516.642, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U3516642.jpg'}, {'end': 4060.722, 'src': 'embed', 'start': 4031.359, 'weight': 0, 'content': [{'end': 4033.663, 'text': 'But this is something which is taking a lot of time.', 'start': 4031.359, 'duration': 2.304}, {'end': 4036.548, 'text': 'Yes, this is taking N1 into N2.', 'start': 4033.803, 'duration': 2.745}, {'end': 4037.589, 'text': "And that's a lot of time.", 'start': 4036.728, 'duration': 0.861}, {'end': 4043.793, 'text': "so we will be trying to optimize this and let's understand how the optimal solution will look like.", 'start': 4038.47, 'duration': 5.323}, {'end': 4047.355, 'text': 'so the optimal solution depends on both the arrays being sorted.', 'start': 4043.793, 'duration': 3.562}, {'end': 4053.438, 'text': "since they are sorted, we will be applying something as a two-pointer approach, and it's going to be very simple.", 'start': 4047.355, 'duration': 6.083}, {'end': 4060.722, 'text': 'what we do is we basically keep two pointers, one at this one and the other one at this,', 'start': 4053.438, 'duration': 7.284}], 'summary': 'Optimizing process taking n1 x n2 time and using a two-pointer approach for sorted arrays.', 'duration': 29.363, 'max_score': 4031.359, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U4031359.jpg'}], 'start': 3318.817, 'title': 'Union and intersection of arrays', 'summary': 'Covers the logic of handling elements in a union array, emphasizing the importance of taking the first element when the union array is empty, and the process of union and intersection of two sorted arrays with their time and space complexities, and the introduction of optimal solutions with improved time complexities.', 'chapters': [{'end': 3362.368, 'start': 3318.817, 'title': 'Union array logic', 'summary': 'Discusses the logic behind handling elements in a union array, emphasizing the importance of taking the first element when the union array is empty and considering the smaller element when the union array has other elements.', 'duration': 43.551, 'highlights': ['The first element should always be taken when the union array is empty, indicated by the condition union array.size equals zero, ensuring that it is considered for the first time.', 'When the union array contains other elements, the smaller element should be chosen, providing a clear decision-making process for handling subsequent elements.']}, {'end': 3666.692, 'start': 3362.788, 'title': 'Union and intersection of sorted arrays', 'summary': 'Discusses the process of union and intersection of two sorted arrays, including the approach, time complexity, and space complexity, and emphasizes the importance of considering sorted arrays for optimal solutions.', 'duration': 303.904, 'highlights': ['The time complexity of the algorithm for union of two sorted arrays is O(n1 + n2), where n1 and n2 are the lengths of the two arrays, as every element is visited once.', 'The space complexity for returning the union is O(n1 + n2) in the worst case if all elements are unique, and no additional loops are used apart from iterating through every element.', 'The process of finding the intersection of two sorted arrays involves checking for corresponding elements and allowing repetition, which results in the intersection array containing the elements present in both arrays.']}, {'end': 4387.619, 'start': 3666.692, 'title': 'Intersection of two sorted arrays', 'summary': 'Explains the brute force approach for finding the intersection of two sorted arrays using a visited array and pseudocode, with a time complexity of o(n1*n2). it then introduces an optimal solution based on the two-pointer approach with a time complexity of o(n1+n2) and no extra space usage.', 'duration': 720.927, 'highlights': ['The brute force approach involves using a visited array to track if an element has been used previously, with a time complexity of O(n1*n2).', 'The optimal solution uses a two-pointer approach with a time complexity of O(n1+n2) and no extra space usage.']}], 'duration': 1068.802, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wvcQg43_V8U/pics/wvcQg43_V8U3318817.jpg', 'highlights': ['The optimal solution uses a two-pointer approach with a time complexity of O(n1+n2) and no extra space usage.', 'The time complexity of the algorithm for union of two sorted arrays is O(n1 + n2), where n1 and n2 are the lengths of the two arrays, as every element is visited once.', 'The space complexity for returning the union is O(n1 + n2) in the worst case if all elements are unique, and no additional loops are used apart from iterating through every element.', 'The process of finding the intersection of two sorted arrays involves checking for corresponding elements and allowing repetition, which results in the intersection array containing the elements present in both arrays.', 'When the union array contains other elements, the smaller element should be chosen, providing a clear decision-making process for handling subsequent elements.', 'The first element should always be taken when the union array is empty, indicated by the condition union array.size equals zero, ensuring that it is considered for the first time.']}], 'highlights': ['The A2Z DSA course covers 456 modules and aims to solve 400+ problems, ensuring learners are well-prepared for DS algorithm interviews globally.', 'The course emphasizes problem-solving techniques, starting with Brute, progressing to Better, and finally reaching Optimal solutions, with a focus on showcasing the thought process in interviews.', 'The chapter introduces the linear search problem with a time complexity of O(n).', 'The optimal solution uses a two-pointer approach with a time complexity of O(n1+n2) and no extra space usage.', 'The process of rotating an array by a specified number of places is demonstrated with examples of rotating by 1, 2, and 3 places, showcasing the shifting and final array after each rotation.', 'The method for rotating an array involves three reversals with time complexity of 2n and space complexity of o(1)', 'The process involves iterating through both arrays, comparing and adding the smallest element to the union list, with an emphasis on not adding duplicate elements.', 'The chapter discusses the union of two sorted arrays, emphasizing the use of a set data structure to efficiently find unique elements and maintain sorted order.', 'The algorithm involves storing a specified number of elements from the beginning of the array, shifting the remaining elements, and then putting the stored elements back, illustrating the process with quantifiable examples.', 'The process of shifting and rotating arrays is explained, involving pseudocode and cleaner code for implementation, along with discussions on time complexity and extra space usage.']}