Robot Collisions | Made Easy | Dry Run | Leetcode 2751 | codestorywithMIK

Subscribers:
92,300
Published on ● Video Link: https://www.youtube.com/watch?v=fkcA9zvP7_w



Duration: 35:30
7,645 views
328


Whatsapp Community Link : https://www.whatsapp.com/channel/0029...
This is the 20th Video of our Playlist "Stack : Popular Interview Problems" by codestorywithMIK

Similar Problem - Leetcode 735 - Asteroid Collision -    • Asteroid Collision | Intuition | Dry ...  

In this video we will try to solve a very good Stack based problem : Robot Collisions | Made Easy | Dry Run | Leetcode 2751 | codestorywithMIK

I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.
Also, please note that my Github solution link below contains both C++ as well as JAVA code.

Problem Name : Robot Collisions | Made Easy | Dry Run | Leetcode 2751 | codestorywithMIK
Company Tags : Will update soon
My solutions on Github(C++ & JAVA) : https://github.com/MAZHARMIK/Intervie...
Leetcode Link : https://leetcode.com/problems/robot-c...


My DP Concepts Playlist :    • Roadmap for DP | How to Start DP ? | ...  
My Graph Concepts Playlist :    • Graph Concepts & Qns - 1 : Graph will...  
My Recursion Concepts Playlist :    • Introduction | Recursion Concepts And...  
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Intervie...
Instagram :   / codestorywithmik  
Facebook :   / 100090524295846  
Twitter :   / cswithmik  
Subscribe to my channel :    / @codestorywithmik  

╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝

Summary :
The given solution is designed to determine the health of robots that survive after potential collisions based on their positions, health levels, and directions. Here's a brief summary of the approach:

Initialization:

The function survivedRobotsHealths takes three inputs: positions, healths, and directions.
The size of the input is stored in n.
A vector indices of size n is initialized to contain values from 0 to n-1.
Sorting by Position:

The indices vector is sorted based on the robots' positions using a lambda function, which allows for accessing the positions via the indices.
Simulation of Robot Movements Using Stack:

A stack st is used to manage robots moving to the right ('R').
As the sorted indices are processed:
If a robot is moving to the right ('R'), its index is pushed onto the stack.
If a robot is moving to the left ('L'), it may collide with robots on the stack.
Collisions are resolved by comparing health values:
If the health of the robot moving left is greater, it continues with reduced health.
If the health of the robot moving right is greater, it remains on the stack with reduced health.
If healths are equal, both robots are destroyed.
Collecting Results:

After processing all collisions, the health values of surviving robots (health greater than 0) are collected into the result vector.
Complexity:

Time Complexity: O(n log n) due to the sorting step.
Space Complexity: O(n) for storing indices and using the stack.
The final result vector contains the health values of the surviving robots after all potential collisions have been resolved.


✨ Timelines✨
00:00 - Introduction
00:25 - Problem Explanation
07:09 - Thought Process
22:21 - Sorting + Lambda
27:26 - Coding on Leetcode


#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #newyear2024




Other Videos By codestorywithMIK


2024-07-22Sort the Jumbled Numbers | 2 Approaches | Leetcode 2191 | codestorywithMIK
2024-07-20Minimum Operations to Make Array Equal to Target | Minimum Number of Increments|Leetcode 3229 & 1526
2024-07-19Build a Matrix With Conditions | BFS | DFS | Detailed Explanation | Leetcode 2392 | codestorywithMIK
2024-07-19Palindrome Partitioning | Using Blue Print | DP On Strings | Leetcode 131 | DP Concepts & Qns-27
2024-07-18Find Valid Matrix Given Row and Column Sums | Simple Approach | Leetcode 1605 | codestorywithMIK
2024-07-18Number of Good Leaf Nodes Pairs | Simple DFS | Dry Run | Leetcode 1530 | codestorywithMIK
2024-07-17Lucky Numbers in a Matrix | 2 Approaches | Dry Run | Leetcode 1380 | codestorywithMIK
2024-07-16Number of Good Leaf Nodes Pairs | Using Graph And BFS | Dry Run | Leetcode 1530 | codestorywithMIK
2024-07-14Step-By-Step Directions From a Binary Tree Node to Another | 2 Approaches | Leetcode 2096
2024-07-13Create Binary Tree From Descriptions | Simplest Approach | Leetcode 2196 | codestorywithMIK
2024-07-12Robot Collisions | Made Easy | Dry Run | Leetcode 2751 | codestorywithMIK
2024-07-11Maximum Score From Removing Substrings | 2 Approaches | With Proof | Leetcode 1717
2024-07-09Reverse Substrings Between Each Pair of Parentheses | 2 Approaches | Leetcode 1190 |codestorywithMIK
2024-07-08Crawler Log Folder | 2 Approaches | Dry Runs | Leetcode 1598 | codestorywithMIK
2024-07-07Average Waiting Time | Simple Simulation | Leetcode 1701 | codestorywithMIK
2024-07-06Range Update Query | Lazy Propagation | Segment Tree Concepts & Qns | Video 7 | codestorywithMIK
2024-07-06Find the Winner of the Circular Game | 3 Approaches | Leetcode 1823 | codestorywithMIK
2024-07-05Pass the Pillow | 2 Approaches | Easy Explanations | Leetcode 2582 | codestorywithMIK
2024-07-05Water Bottles | 3 Approaches | Easy Explanations | Leetcode 1518 | codestorywithMIK
2024-07-02Minimum Difference Between Largest and Smallest Value in Three Moves | 2 Approaches | Leetcode 1509
2024-07-02Merge Nodes in Between Zeros | 2 Approaches | Leap Of Faith | Leetcode 2181 | codestorywithMIK