id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
1
{ "code": "class Solution {\npublic:\n std::vector<int> survivedRobotsHealths(std::vector<int> const& positions, std::vector<int>& healths, std::string const& directions) {\n std::vector<std::size_t> sorted(std::size(positions));\n std::iota(std::begin(sorted), std::end(sorted), 0);\n std::ran...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
1
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n int n = positions.size();\n\n vector<pair<int, int>> posIdxPair(n);\n for (int i = 0; i < n; ++i) {\n posIdxPair[i] = {positions[i], i};\n }\n sort(posIdxP...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
1
{ "code": "#include <vector>\n#include <algorithm>\n#include <stack>\n\nusing namespace std;\n\nstruct Robot {\n int pos;\n int health;\n char dir; // direction: 'L' or 'R'\n int index; // original index\n};\n\nclass Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vecto...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
1
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n int n = positions.size();\n vector<pair<int, int>> robots;\n for (int i = 0; i < n; i++) {\n robots.emplace_back(positions[i], i);\n }...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
1
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& health, string directions) {\n vector<pair<int,int>> indexMap;\n for(int i1=0;i1<positions.size();++i1){\n indexMap.push_back({positions[i1],i1});\n }\n sort(indexMap...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
1
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n vector<pair<int,int>>v1;\n for(int i=0;i<positions.size();i++)\n {\n v1.push_back({positions[i],i});\n }\n sort(v1.begin(), v1....
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
1
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions,\n vector<int>& healths, string direction) {\n\n vector<pair<int, int>> v;\n vector<int> ans;\n int np = positions.size();\n for (int i = 0; i < positions...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
1
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n stack<int>s;\n int n =positions.size();\n vector<pair<pair<int,int>,pair<int,char>>> r(n);\n vector<int>ans;\n vector<pair<int,int>>temp;\...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
1
{ "code": "struct Robot {\n int i;\n int x;\n int health;\n char dir;\n};\n\nclass Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& pos, vector<int>& hs, string dirs) {\n int n = pos.size();\n vector<Robot> rs;\n rs.reserve(n);\n for (int i = 0; i < n; ++...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
1
{ "code": "struct Robot {\n int i;\n int x;\n int health;\n char dir;\n};\n\nclass Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& pos, vector<int>& hs, string dirs) {\n int n = pos.size();\n vector<Robot> rs;\n rs.reserve(n);\n for (int i = 0; i < n; ++...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
1
{ "code": "struct Robot {\n int i;\n int x;\n int health;\n char dir;\n};\n\nclass Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& pos, vector<int>& hs, string dirs) {\n int n = pos.size();\n vector<Robot> rs;\n rs.reserve(n);\n for (int i = 0; i < n; ++...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
1
{ "code": "\nstruct Robot{\n int health;\n int position;\n char direction; \n int index; \n};\n\nbool comparator(Robot &a,Robot &b){\n return a.position<b.position;\n}\n\nclass Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
1
{ "code": "class Solution {\n public:\n struct robot {\n int originalIndex;\n int position;\n int health;\n char direction;\n } temp;\n\n static bool compareOriginalIndex(const robot& a, const robot& b) {\n return a.originalIndex < b.originalIndex;\n }\n\n static bo...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
1
{ "code": "struct Robot\n{\n int posit;\n int health;\n char dir;\n int index;\n bool operator<(Robot const & b)\n {\n return this->posit<b.posit;\n }\n};\nbool judge(Robot a,Robot b)\n{\n return a.index<b.index;\n}\nclass Solution {\npublic:\n vector<int> survivedRobotsHealths(vecto...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
1
{ "code": "struct Robot\n{\n int posit;\n int health;\n char dir;\n int index;\n bool operator<(Robot const & b)\n {\n return this->posit<b.posit;\n }\n};\nbool judge(Robot a,Robot b)\n{\n return a.index<b.index;\n}\nclass Solution {\npublic:\n vector<int> survivedRobotsHealths(vecto...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
1
{ "code": "class Solution {\n typedef struct robot{\n int id;\n int pos;\n int health;\n char dir;\n }robot;\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n int n=positions.size();\n vector<robot> robo...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
1
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions,\n vector<int>& healths, string directions) {\n vector<int> result;\n map<int, int> mp; // position -> health mapping for the surviving robots\n stack<pair<int, ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& health, string directions) {\n vector<pair<pair<int, int>, int>> v;\n for (int i = 0; i < positions.size(); i++) {\n v.push_back({{positions[i], health[i]}, i});\n }\n\n ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "struct Robot\n{\n int posit;\n int health;\n char dir;\n int index;\n bool operator<(Robot const & b)\n {\n return this->posit<b.posit;\n }\n};\nbool judge(Robot a,Robot b)\n{\n return a.index<b.index;\n}\nclass Solution {\npublic:\n vector<int> survivedRobotsHealths(vecto...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n\n class Robot{\n public:\n int position;\n int index;\n int health;\n char direction;\n Robot(int position,int index,int health,char direction){\n this->position = position;\n this->index = index;\n th...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n vector<pair<pair<int,int>,pair<int,char> > > arr;\n for(int i =0;i<positions.size();i++){\n arr.push_back(make_pair(make_pair(positions[i],i),make_p...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n struct Robot{\n int index;\n int position;\n int health;\n char direction;\n };\n\n void handleCollisions(stack<Robot>& st, Robot& robot) {\n // collide with robots going right with less healths -> current robot wins\n while (!s...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n struct ROBOT\n {\n int no;\n int pos;\n int hp;\n char dir;\n };\n\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n vector<ROBOT> r;\n\n int n = positions.size();\n ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n stack<pair<int,pair< char,int>>> st;\n int n = positions.size();\n...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n vector<int> ans;\n vector<tuple<int, int, char, int>> vec;\n for(int i = 0; i<healths.size(); i++)\n {\n vec.push_back({positions[i], ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n void handleCollision(stack<pair<int, pair<int, pair<int, int>>>>& st, pair<int, pair<int, pair<int, int>>> curr) {\n while (!st.empty() && st.top().second.second.first == 'R' && st.top().second.first < curr.second.first) {\n st.pop();\n curr.secon...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "bool compare(const pair<int, pair<int, pair<int, char>>> a, const pair<int, pair<int, pair<int, char>>> b) {\n return a.first < b.first;\n}\nclass Solution {\npublic:\n\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n stack<pair<int,pair<...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\nstruct Robot{\n int p;\n int h;\n int d;\n \n int i;\n};\n \nstatic bool compare(const Robot &a,const Robot &b){\n return a.p < b.p;\n}\n vector<int> survivedRobotsHealths(vector<int>& pos, vector<int>& heal, string& direc) {\n int n=pos.size();\n ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string& directions) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n vector<array<int, 4>> robots;\n stack<array<int, 4>> st;\n ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n vector<pair<int, pair<char, int>>> kit;\n\n for(int i = 0; i < positions.size(); i++) {\n kit.push_back({positions[i], {directions[i], healths[i]}})...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n ios_base::sync_with_stdio(false); \n cin.tie(nullptr); \n cout.tie(nullptr);\n struct Robot {\n int pos;\n int hp;\n ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n vector<pair<int,pair<int,char>>> v;\n vector<int> ans;\n int n=positions.size();\n for(int i=0;i<n;i++){\n v.push_back({positions[i],{...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n\nvector<int> survivedRobotsHealths(vector<int> &positions, vector<int> &healths, string directions)\n{\n\n vector<int> st;\n unordered_map<int, int> mp;\n vector<int> ans;\n for (int i = 0; i < positions.size(); ++i)\n mp[positions[i]] = i;\n\n sort(positio...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Robot {\n public:\n int id;\n int pos;\n int health;\n int direction;\n Robot(int id, int pos, int health, int direction){\n this->id = id;\n this->pos = pos;\n this->health = health;\n this->direction = direction;\n }\n};\nclass Solution {\npublic:\n ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions,\n vector<int>& healths, string directions) {\n int n = positions.size();\n unordered_map<int, int> posToIdx;\n for (int i = 0; i < n; ++i) {\n posToI...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n int n = positions.size();\n vector<vector<int>> vec(n);\n for(int i=0;i<n;i++){\n vec[i] = {positions[i], i};\n }\n sort(vec.be...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n stack<int> s;\n int n=positions.size();\n map<int,pair<int,char> >m;\n for(int i=0;i<n;i++){\n m[positions[i]]={healths[i],directions[...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n struct robot{\n int pos;\n int health;\n char dir;\n int idx;\n bool dead = false;\n };\n static bool sortBots(robot& a, robot& b){\n return (a.pos < b.pos);\n }\n static bool sortBackBots(robot& a, robot& b){\n ret...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n int n=positions.size();\n vector<int> ans;\n map<int, pair<int,int>> robs;\n map...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "const static auto startupOptimization = []() {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions,\n vector<int>&...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "const static auto startupOptimization = []() {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions,\n vector<int>&...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "/* clang-format off */\n#define cerr cout\nnamespace __DEBUG_UTIL__ { void print(const char *x) { cerr << x; } void print(bool x) { cerr << (x ? \"T\" : \"F\"); } void print(char x) { cerr << '\\'' << x << '\\''; } void print(signed short int x) { cerr << x; } void print(unsigned short int x) { cerr << x; ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n int n = positions.size(); \n vector<tuple<int,int,int,char>> v; \n stack<tuple<int,int,int,char>> st; \n \n for (int i = 0; i < n; i++)...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n int n = positions.size();\n vector<tuple<int,int,char>> v(n);\n for (int i = 0; i < n; i++){\n get<0>(v[i]) = positions[i];\n get<...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n int n = positions.size();\n vector<tuple<int,int,char>> v(n);\n for (int i = 0; i < n; i++){\n get<0>(v[i]) = positions[i];\n get<...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n int n = positions.size();\n vector<pair<int, pair<int, char>>> robots(n);\n for (int i = 0; i < n; ++i) {\n robots[i] = make_pair(positions[i...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n int n = positions.size();\n vector<tuple<int, int, char>> robots(n);\n for (int i = 0; i < n; ++i) {\n robots[i] = {positions[i], healths[i],...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n stack<pair<int, int>> st;\n int n = directions.size();\n vector<int> ans(n, -1);\n\n unordered_map<int, int> rev;\n for(int i = 0; i < n; ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n int n = positions.size();\n vector<int> idx;\n unordered_map<int, int> mp;\n for (int i = 0; i < n; i++) {\n idx.push_back(i);\n ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& pos, vector<int>& he, string dir) {\n int n=pos.size();\n if(n==1){\n return he;\n }\n int cr=0,cl=0;\n \n //pos,heal,dir\n vector<pair<int,pair<int,char>>> p(n);\n ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& pos, vector<int>& he, string dir) {\n int n=pos.size();\n if(n==1){\n return he;\n }\n int cr=0,cl=0;\n \n //pos,heal,dir\n vector<pair<int,pair<int,char>>> p(n);\n ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n bool static cust(vector<int>&a,vector<int>&b){\n return a[1]<b[1];\n }\n vector<int> survivedRobotsHealths(vector<int>& l, vector<int>& h, string d) {\n int n=l.size();\n stack<vector<int>>st;\n vector<pair<int,int>>l1;\n for(int i=0;i...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& posn, vector<int>& health, string dirn) {\n unordered_map<int,int>index;\n int n=posn.size();\n for(int i=0;i<n;i++){\n index[posn[i]]=i;\n }//keeping track of original index with respect to...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class val{\n public:\n int pos;\n int heal;\n char dir;\n};\n\n\nclass Solution {\n\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n int n=healths.size();\n stack<val> s;\n map<int,int>m;\n vector<in...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n ios_base::sync_with_stdio(false); \n cin.tie(nullptr); \n cout.tie(nullptr);\n struct Robot {\n int pos;\n int hp;\n ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n int n = healths.size();\n map<int,int> mp;\n for(int i=0;i<n;i++)\n {\n mp[positions[i]] = i+1;\n }\n vector<pair<int,pa...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n int n = positions.size();\n for(int i=0;i<n;i++)\n {\n if(directions[i]=='L') healths[i]=-healths[i];\n }\n vector<pair<int,int...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& position, vector<int>& health, string direction) {\n map<int, pair<int,char>> m;\n for(int i=0;i<position.size();i++)\n m[position[i]] = {health[i],direction[i]};\n\n stack<int> l,r;\n set<int> ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n map<int,int> robotToPosition;\n int n = positions.size();\n for (int i=0;i<n;i++)\n {\n robotToPosition[positions[i]]=i;\n }\n\...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n int n = positions.size();\n vector<pair<int, pair<int, char>>> robots; \n\n for (int i = 0; i < n; i++) {\n robots.push_back({positions[i], {he...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n vector<pair<int,int>> rel;\n unordered_map<int,int> pos;\n for(int i=0; i< positions.size(); i++){\n rel.push_back({positions[i],i});\n ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n int n=positions.size();\n map<int,pair<int,char>> mp;\n for(int i=0;i<n;i++)\n {\n mp[positions[i]].first=healths[i];\n mp[...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
2
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n stack<int> st;\n vector<vector<int>> v;\n for(int i=0;i<positions.size();i++){\n v.push_back({positions[i],healths[i],directions[i],i});\n ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "#define ll int\nclass Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n ll n = directions.size();\n map<ll, ll> m; // {indx, health}\n stack<pair<ll, ll>> stk;\n vector<tuple<ll, ll, char>> v;\n ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n vector<tuple<int, int, char>> robots;\n stack<int> stk;\n unordered_map<int, int> umap;\n vector<pair<int, int>> robotPositions;\n bool ke...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n \n vector<vector<int>> vec;\n for(int i=0; i<positions.size(); i++)\n {\n vec.push_back({positions[i], healths[i], directions[i], i});...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "#include<bits/stdc++.h>\ntypedef long long ll;\n \n#define rep(i,a,b) for(ll i=a;i<b;i++)\n#define revrep(i,a,b) for(ll i=a;i>=b;i--)\n#define yes cout << \"YES\" << endl;\n#define no cout << \"NO\" << endl;\n#define vi vector<ll>\n#define pb push_back\n#define fast_cin() ios_base::sync_with_stdio(false); ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions,\n vector<int>& healths, string directions) {\n deque<pair<int, int>> st;\n vector<int> ans;\n vector<vector<int>> v;\n vector<pair<int, int>> temp;\n ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& p, vector<int>& h, string d) {\n stack<int> st;\n int n = p.size();\n vector<pair<int, pair<int, char>>> com;\n map<int,int>mp;\n for (int i = 0; i < n; i++) {\n mp[p[i]] = i;\n ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n ios_base::sync_with_stdio(false); \n cin.tie(nullptr); \n cout.tie(nullptr);\n struct Robot {\n int pos;\n int hp;\n ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n ios_base::sync_with_stdio(false); \n cin.tie(nullptr); \n cout.tie(nullptr);\n struct Robot {\n int pos;\n int hp;\n ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n vector<vector<int> >v(positions.size(), vector<int>(4));\n for(int i=0;i<positions.size();i++){\n v[i][0]=positions[i];\n }\n for(int ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n vector<vector<int>> data;\n unordered_map<int, int> ans;\n stack<pair<int, int>> s;\n int i = 0;\n int j = healths.size()-1;\n for(...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& pos,vector<int>& h,string s) {\n stack<int>st;\n int n=h.size();\n map<int,int>mp,fin;\n for(int i=0;i<n;i++)\n {\n mp[pos[i]]=i;\n }\n vector<pair<int,pair<int,char>>>v...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "struct Robot{\npublic:\n int health;\n int pos;\n bool left;\n bool alive;\n\n Robot(int h, int p, bool l): health{h}, pos{p}, left{l}, alive{true} {}\n\n bool willCollide(Robot* r) const {\n if (left != r->left) {\n // check both coming near other or going away\n ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n int n = positions.size();\n vector<vector<int>>temp(n, {0,0,0});\n for(int i=0;i<n;i++){\n temp[i][0] = positions[i];\n temp[i][1]...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& pos, vector<int>& hs, string dirs) {\n int n = pos.size();\n vector<vector<int>>a(n, vector<int>(4));\n for(int i = 0; i < n; i++) {\n a[i][0] = pos[i];\n a[i][1] = hs[i];\n a...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& pos, vector<int>& h,\n string s) {\n int n = s.size();\n vector<vector<int>> v;\n for (int i = 0; i < n; i++) {\n v.push_back({pos[i], h[i], i});\n }\n ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n map<int, pair<int, char>> mp;\n\n for(int i = 0; i < positions.size(); i++) mp[positions[i]] = {healths[i], directions[i]};\n\n stack<int> st;\n\n ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n vector<vector<int>> robs;\n int n=positions.size();\n for(int i=0;i<n;i++)\n {\n if(directions[i]=='R')\n robs.push_bac...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\nvector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n\tvector<int>ans;\n\tset<pair<int, pair<int, int>>> L, R;\n\tfor (int i = 0; i < positions.size(); i++) {\n\t\tif (directions[i] == 'L') {\n\t\t\tR.insert(make_pair(positions[i],...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n int n=positions.size();\n unordered_map<int,int>m1;\n unordered_map<int,char>m2;\n vector<int>v;\n for(int i=0;i<n;i++){\n v.pu...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n const int n = directions.size();\n vector<int> res;\n vector<int> pos;\n unordered_map<int, int> pos_res;\n string dir;\n\n vector<...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n int n = positions.size();\n vector<Robot> robots(n);\n for (int i=0; i<n; i++) {\n Robot r(positions[i], healths[i], directions[i]=='R');\n ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n int n = positions.size();\n vector<Robot> robots(n);\n for (int i=0; i<n; i++) {\n robots[i].pos = positions[i];\n robots[i].healt...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n\n stack<int> stc;// index\n vector<int> ret , ans;\n vector<vector<int>> robots;\n int n = positions.size();\n for (int i =0;i < n;i++) ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n int n = positions.size();\n stack<int> s;\n map<int, int> healthMap, indexMap;\n // 0 -> 4, 1 -> 3\n vector<int> temp = positions;\n ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n vector<vector<int>> v;\n map<int,int> ans;\n int n=positions.size();\n for(int i=0;i<n;i++){\n v.push_back({positions[i],healths[i],di...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions,\n vector<int>& healths, string directions) {\n vector<vector<int>> robots;\n stack<vector<int>> stk;\n\n for (int i = 0; i < positions.size(); i++) {\n ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& p, vector<int>& h, string d) {\n vector<vector<int>> arr;\n stack<pair<int, int>> st;\n int n = p.size();\n\n // Prepare the robot data and sort by position\n for (int i = 0; i < n; i++) {\n ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n int n = positions.size();\n vector<int> dir(n);\n for(int i=0; i<n; ++i){\n if(directions[i]=='L') dir[i]=-1; // L--> -1\n else ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n int n=positions.size();\n map<int ,pair<int,char>>mp;\n map<int,int>pos;\n for(int i=0;i<n;i++){\n mp[positions[i]]={healths[i],direct...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\nbool comp(vector<int> a,vector<int> b){\n return a[0]<=b[0];\n}\n vector<int> survivedRobotsHealths(vector<int>& p, vector<int>& h, string d) {\n stack<vector<int>> s;\n int n=p.size();\n vector<vector<int>> v(n);\n for(int i=0;i<n;i++){\n ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& pos, vector<int>& hp, string dir) {\n\n vector<int> ans (pos.size(), 0);\n unordered_map<int, int> index;\n\n for(int i=0;i<pos.size(); i++)\n index[pos[i]]=i;\n\n unordered_map<int, pair<in...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& pos, vector<int>& hp, string dir) {\n\n vector<int> ans (pos.size(), 0);\n unordered_map<int, int> index;\n\n for(int i=0;i<pos.size(); i++)\n index[pos[i]]=i;\n\n unordered_map<int, pair<in...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions,\n vector<int>& healths, string directions) {\n\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n\n\n ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions,\n vector<int>& healths, string directions) {\n\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n\n\n ...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n int n = positions.size();\n vector<vector<int>> robots;\n\n for (int i = 0; i < n; ++i) {\n robots.push_back({positions[i], healths[i], direc...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n vector<int> survivedRobotsHealths(vector<int>& positions, vector<int>& healths, string directions) {\n int n = positions.size();\n vector<vector<int>> robots;\n\n for (int i = 0; i < n; ++i) {\n robots.push_back({positions[i], healths[i], direc...
2,846
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p> <p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <stron...
3
{ "code": "class Solution {\npublic:\n static bool mycmp(pair<int,pair<int,int>> &a,pair<int,pair<int,int>> &b){\n return a.first<b.first;\n }\n vector<int> survivedRobotsHealths(vector<int>& pos, vector<int>& health,\n string s) {\n int n=pos.size();\n vector<pair<int,pair<int,int>>>...