id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 1 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n int n=arr.size();\n queue<int>q;\n vector<int>vis(n,0);\n q.push(start);\n vis[start]=1;\n \n while(!q.empty()){\n \n int node =q.front();\n cout<<node<<endl;\n q.pop();\n if(arr[node]==0... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 1 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n int N=arr.size();\n vector<int> v(N,0);\n queue<int> q;\n q.push(start);\n while(!q.empty())\n {\n int n=q.size();\n for(int i=0;i<n;i++)\n {\n ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 1 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n int n = arr.size();\n vector<int> visited(n, 0);\n queue<int> q;\n q.push(start);\n while (!q.empty()) {\n int ind = q.front();\n q.pop();\n if (ind < 0 || ind >... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 1 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n int n = arr.size();\n queue<int> q;\n vector<int> vis(n, 0);\n q.push(start);\n\n while(!q.empty())\n {\n int pos = q.front();\n q.pop();\n\n if(arr[pos] ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 1 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n int n = arr.size();\n queue<int> q;\n vector<bool>seen(n);\n \n q.push(start);\n seen[start] = true;\n \n while(!q.empty()) {\n int currIndex = q.front();\n ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 1 | {
"code": "class Solution {\npublic:\n bool bfs(vector<int> arr, int start, vector<int> &mp){\n\n queue<int> q;\n q.push(start);\n mp[start] = 1;\n\n while(!q.empty()){\n int t = q.front();\n q.pop();\n if(arr[t] == 0){\n return true;\n }\n\n \n if(t ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 1 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n /** recursive **/\n if(arr[start] == 0)\n return true;\n if(arr[start] == -1)\n return false;\n int n = arr.size();\n int cur = arr[start];\n arr[start] = -1;\n ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 1 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int curr) {\n const int n = arr.size() - 1;\n if (curr < 0 || curr > n) return false;\n if (arr[curr] == -1) return false;\n if (arr[curr] == 0) return true;\n int val = arr[curr]; \n arr[curr] = -1; \n... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 1 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n queue<int> q;\n vector<int> v1;\n for(int i=0;i<arr.size();i++)\n {\n v1.push_back(0);\n }\n q.push(start);\n while(!q.empty())\n {\n int temp = q.fron... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 1 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start)\n {\n if (arr[start] == 0) {\n return true;\n }\n std::list<int> list;\n int len = arr.size();\n std::vector<bool> visited(len, false);\n list.push_back(start);\n visited... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 1 | {
"code": "class Solution {\npublic:\n\n bool solve(vector<int>&arr, int i ){\n \n\n if(i>=arr.size() || i<0 || arr[i]<0) return false;\n if(arr[i] == 0) return true;\n arr[i]*=-1;\n return solve(arr, i+abs(arr[i])) || solve(arr, i-abs(arr[i]));\n \n \n ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 1 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& a, int s) {\n queue<int>q;\n int n = a.size();\n vector<int>vis(n);\n vis[s] = 1;\n q.push(s);\n while(!q.empty()){\n vector<int>v;\n while(!q.empty()){\n v.push_back(q.f... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 1 | {
"code": "class Solution {\n int visited[50001];\npublic:\n bool canReach(vector<int>& arr, int start) {\n if(start < 0 || start >= arr.size()){\n return false;\n }\n if(arr[start] == 0){\n return true;\n }\n if(visited[start] == 1){\n return ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 1 | {
"code": "class Solution {\npublic:\n\n bool canReach(vector<int>& arr, int start) \n {\n if(start < 0 || start >= arr.size())\n {\n return false;\n }\n if(arr[start] == 0)\n {\n return true;\n }\n if(arr[start] < 0)\n {\n ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 1 | {
"code": "class Solution {\n int dp[50005];\n int n;\npublic:\nint f( int i , vector<int>&arr){\n if(i>=n || i<0) return 0;\n if(arr[i]==0) return 1;\n \n\n if(dp[i]!=-1) return dp[i];\n dp[i] = 0;\n\n int move_left= f(i-arr[i] , arr);\n int move_right= f(i+ arr[i] , arr);\n\n if(mov... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n int n = arr.size();\n set<int> found; found.insert(start);\n stack<int> s; s.push(start);\n set<int>::iterator it; int v; int w;\n while( s.empty() == false ){\n \n v = s.t... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n bool func(vector<int>& arr, vector<int>& vis,int index){\n if(vis[index]!=0) return false;\n if(arr[index]==0) return true;\n int left = index-arr[index];\n int right = index+arr[index];\n vis[index]=1;\n bool flag= false;\n ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n bool func(vector<int> const& arr, int start, vector<pair<bool, bool>> &dp) {\n if (arr[start] == 0)\n return true;\n\n if (dp[start].first && dp[start].second)\n return false;\n\n int left = start - arr[start];\n int right = s... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n vector<int> a;\n int visited[50000];\n\n int dfs(int i) {\n if(a[i] == 0) return 1;\n\n if(visited[i]) return 0;\n\n int ans = 0;\n visited[i] = 1;\n if(i + a[i] < a.size()) {\n ans = dfs(i+a[i]);\n }\n if(i - ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& nums, int start) {\n unordered_map<int , bool> vm;\n stack<int>st;\n int ci=start;\n vm[start]=true;\n\n\n if(nums[ci]==0 && ci>=0 && ci<nums.size())\n return true;\n\n int fi= ci+nums[ci];\n int... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\nbool vis[50001];\nint dp[50001];\nbool f(vector<int>& arr, int cur){\n if(cur>=arr.size() || cur <0) return 0;\n if(arr[cur] == 0) return 1;\n if(vis[cur] == true) return 0;\n vis[cur]=true;\n if(dp[cur] !=-1) return dp[cur];\n int increment = f(arr, cur+arr[cur... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n bool dfs(vector<int> &arr, vector<int> &vis, int i){\n if( arr[i] == 0) return true;\n vis[i] = 1;\n if((i+arr[i])<arr.size() && vis[i+arr[i]] == 0){\n if(dfs(arr, vis, i+arr[i])) return true;\n }\n if((i-arr[i])>=0 && vis[i-arr[... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n int n = arr.size();\n vector<int>visited(n,0);\n return f(arr,n,start,visited);\n }\n bool f(vector<int>&arr,int n,int i,vector<int>&visited)\n {\n if(i<0 || i>=n || visited[i]!=0)\n ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n int n = arr.size();\n bool flag = false;\n for(int i = 0; i < n; i++){\n if(arr[i] == 0){\n flag = true; break;\n }\n }\n if(flag == false) return false;\n\n... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n int n=arr.size();\n queue<int> q;\n unordered_set<int> visit;\n\n q.push(start);\n visit.insert(start);\n\n while(!q.empty()){\n int index=q.front();\n q.pop();\n\n ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n unordered_set<int> Zeros;\n for (int i=0; i<arr.size(); i++){\n if (arr[i]== 0){\n Zeros.insert(i);\n }\n }\n queue<int> Q;\n Q.push(start);\n int Piv... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n bool solve(int index,vector<int>&dp,vector<int>& arr,int n ){\n //base case\n if(index<0 || index>=n) return false;\n if(dp[index]!=-1) return dp[index];\n\n if(arr[index]==0) return true;\n \n dp[index]=0;\n //if forward\n ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) \n {\n int n=arr.size();\n queue<int>q;\n q.push(start);//idx\n map<int,int>m;\n m[start]=1;\n while(!q.empty())\n {\n int curr_idx=q.front();q.pop();\n if(arr... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n if (arr[start] == 0) {\n return true;\n }\n \n vector<int> visited(arr.size(), 0);\n return dfs(arr, visited, start);\n }\n\n bool dfs(vector<int>& arr, vector<int>& visited, in... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n int dp[500005];\n int solve(vector<int>&arr,int i){\n if(i>=arr.size() || i<0)return 0;\n if(arr[i]==0)return 1;\n if(dp[i]!=-1)return dp[i];\n dp[i]=0;\n int take = solve(arr,i+arr[i]);\n int backtake =solve(arr,i-arr[i]);\n ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n std::vector<int> neighbors(std::vector<int>& arr, int pos) {\n std::vector<int> nbrs;\n const int left = pos + arr[pos];\n const int right = pos - arr[pos];\n\n if (left >= 0 && left < arr.size()) nbrs.push_back(left);\n if (right >= 0 && ri... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n bool helper(vector<int>& arr, int start, vector<pair<bool, bool>>& visited, bool& flag) {\n if(flag || start >= arr.size() || start < 0 || visited[start].first) return false;\n visited[start].first = true;\n if(arr[start] == 0) {\n flag = true;... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n bool helper(vector<int>& arr, int start, vector<pair<bool, bool>>& visited, bool& flag) {\n if(flag || start >= arr.size() || start < 0 || visited[start].first) return false;\n visited[start].first = true;\n if(arr[start] == 0) {\n flag = true;... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n bool jumpHelper(vector<int> &arr, int i,vector<int> &dp){\n if(i>=arr.size() ||i<0) return false;\n if(arr[i]==0) return true;\n if(dp[i]==1) return false;\n dp[i]=1;\n bool op1=jumpHelper(arr,i+arr[i],dp);\n bool op2=jumpHelper(arr,i... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n bool solve(vector<int>&arr,int index,vector<int>&visited){\n if(index>=arr.size() || index<0) return 0;\n if(arr[index]==0) return 1;\n if(visited[index]) return 0;\n visited[index]=true;\n return solve(arr,index+arr[index],visited) || solve... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n int solve(int idx, int n,vector<int>&arr,vector<int>&check,int t[50001]){\n if(idx>=n || idx<0)return 0;\n if(t[idx] != -1)return t[idx];\n if(arr[idx]==0)return 1;\n if(check[idx]==1)return false;\n check[idx]=1;\n int aage = solve(i... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n bool r(vector<int>& arr, int start,vector<int>&visited,vector<int>&dp){\n if(start<0 || start>=arr.size() || visited[start]==1){\n return false;\n }\n if(arr[start]==0)return true;\n if(dp[start]!=-1){\n return dp[start];\n ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n bool isReachable(vector<int> &arr, int cur, vector<int> &memo, vector<int> &visited){\n\n if( cur < 0 || cur >= arr.size() || visited[cur] ){\n return false;\n }\n\n if( arr[cur] == 0 ){\n return true;\n }\n\n visited[c... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\nprivate:\n bool is_valid(int ind, int n) {\n return ind >= 0 && ind < n;\n }\n\n bool f(vector<int>& arr, int st, vector<int>& vis, vector<int>& dp) {\n if (dp[st] != -1) return dp[st];\n if (arr[st] == 0) return dp[st] = true;\n\n vis[st] = 1;\n\n ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n bool solve(int i, vector<int>& arr, vector<int>& vis, int n, vector<int>& dp) {\n if(i >= n || i < 0 || vis[i] == 1) return false;\n if(arr[i] == 0) return true;\n\n if(dp[i] != -1) return dp[i];\n\n vis[i] = 1;\n bool right = solve(i + arr[... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n\nbool f(int ind,vector<int> &arr,vector<int> &vis, vector<int> &dp){\n // base case\n if (arr[ind]==0){\n return true;\n }\n if (ind>=arr.size()||ind<0){\n return false;\n }\n \n if (vis[ind]){\n return false;\n }\n if (dp[ind]!=-1)... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n vector<int> dp;\n vector<int> vis;\n int n;\n int canr(vector<int>& arr, int start) {\n if(start >= n || start < 0 || vis[start]) return 0;\n if(dp[start]!=-1) return dp[start];\n if(arr[start]==0) return dp[start]=1;\n vis[start]=1;\n ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n unordered_map<int,int>m;\n int n= arr.size();\n \n for(int i=0;i<arr.size();i++)\n {\n int x =arr[i];\n if(x == 0)\n m[i]++;\n }\n unordered_map<in... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n if(arr[start] == 0) {\n return true;\n }\n\n if(arr.size() == 1) {\n return true;\n }\n // stores all the indices that can be reached by jumping\n unordered_set<int>... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n if(arr[start] == 0) {\n return true;\n }\n\n if(arr.size() == 1) {\n return true;\n }\n // stores all the indices that can be reached by jumping\n unordered_set<int>... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\nbool ispossible(int start,vector<int>&arr,vector<int>&visited,vector<int>&dp){\n if(start<0||start>=arr.size())return false;\n if(arr[start]==0)return true;\n if(visited[start]==1){\n return false;\n }\n if(dp[start]!=-1)return dp[start];\n visited[start]... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "#pragma GCC optimize (\"O3,unroll-loops\")\n#pragma GCC target (\"avx2,bmi,bmi2,lzcnt,popcnt\")\n\nclass Solution {\npublic:\n vector<bool> explored;\n\n bool explore(vector<int> &nums, int i) {\n if (i < 0 || i >= nums.size() || explored[i]) return false;\n explored[i] = true;\n ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n int n;\n bool solve(vector<int>& arr, int start,vector<bool>&vis){\n if(start<0 || start>=n || vis[start])\n return 0;\n if(arr[start]==0)\n return 1;\n vis[start]=1;\n return solve(arr,start+arr[start],vis)||solve(arr,start-arr[st... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "const static auto _ = []() { ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }();\nclass Solution {\npublic:\n bool solve(vector<int>& arr,int index,vector<bool>& visited){\n if(index<0 || index>=arr.size() || visited[index])\n return false;\n if(!arr[index]){\n ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n int n = arr.size();\n vector<int> done(n);\n function<bool(int)> dfs = [&](int u) {\n if(u<0 || u>=n || done[u]) return false;\n if(arr[u]==0) return true;\n done[u] = 1;\n ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 2 | {
"code": "class Solution {\npublic:\n\n bool dfs(vector<int>& arr, int idx, vector<bool>& visited) {\n if (idx < 0 || idx >= arr.size() || visited[idx]) {\n return false;\n }\n if (arr[idx] == 0) {return true;}\n visited[idx] = true;\n return(dfs(arr, idx - arr[idx], ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n\n bool dfs(vector<int>& arr, int idx, vector<bool>& visited) {\n if (idx < 0 || idx >= arr.size() || visited[idx]) {\n return false;\n }\n if (arr[idx] == 0) {return true;}\n visited[idx] = true;\n return(dfs(arr, idx - arr[idx], ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n\n bool canReachHelper(vector<int>& arr, int start, vector<bool>& isVisited) {\n if(arr[start] == 0) return true;\n if(isVisited[start]) return false;\n isVisited[start] = true;\n\n if(start + arr[start] < arr.size()) {\n if(canReachHelpe... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n int n = arr.size();\n queue<int> q;\n q.push(start);\n\n unordered_set<string> visited;\n\n while (!q.empty()) {\n int cur = q.front();\n q.pop();\n\n if(arr[cur... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n int n = arr.size();\n queue<int> q;\n q.push(start);\n\n unordered_set<string> visited;\n\n while (!q.empty()) {\n int cur = q.front();\n q.pop();\n\n if(arr[cur... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\nvector<int>dp;\n bool solve(vector<int>& nums, int i, vector<bool>& visited) {\n if (i < 0 || i >= nums.size() || visited[i]) return false;\n \n if (nums[i] == 0) return true;\n if(dp[i]!=-1)\n {\n return dp[i];\n }\n ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n int help(vector<int>& arr, int start,vector<bool>&dp,vector<int> &v){\n if(start<0 || start>= arr.size())return false;\n if(v[start]!=-1)return v[start];\n if(dp[start])return false;\n if(arr[start]==0)return true;\n dp[start]=true;\n bool x... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution{\nprivate:\n void f(vector<bool>& vis,int node,vector<int> &arr){\n vis[node]=true;\n int n=arr.size();\n if(node+arr[node]<n && vis[node+arr[node]]==false) f(vis,node+arr[node],arr);\n if(node-arr[node]>=0 && vis[node-arr[node]]==false) f(vis,node-arr[node],arr);\n }\npublic... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool helper(vector<int>& arr, vector<bool>& dp, int start, int n) {\n if(start>=n || start<0)\n return false;\n \n if(arr[start]==0 || dp[start]==true) {\n return dp[start] = true;\n }\n\n dp[start] = true;\n aut... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n vector<bool> visited(arr.size(), false);\n dfs(start,arr, visited);\n for (auto num : visited) cout << \" \" << num << endl;\n for (int i = 0; i < arr.size(); i++) {\n if (arr[i] == 0 and vi... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n int n = arr.size();\n vector<bool> dp(n+1 , false);\n return solve(start , dp , arr);\n }\n\n bool solve( int i , vector<bool> & dp , vector<int> & arr){ \n if(i>= arr.size() || i<0 || dp[i])... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "// class Solution {\n// public:\n// int final_ans=0;\n// int jump(int ind,vector<int>&arr,int start,int n,vector<int>&dp){\n// //if(ind<0 || ind>=n) return false;\n// if(ind+arr[ind]>=n || ind-arr[ind]<0) return 0;\n// if(arr[ind]==0) {\n// final_ans=1;\n// return dp[ind]=1;\n// }... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "// class Solution {\n// public:\n// int final_ans=0;\n// int jump(int ind,vector<int>&arr,int start,int n,vector<int>&dp){\n// //if(ind<0 || ind>=n) return false;\n// if(ind+arr[ind]>=n || ind-arr[ind]<0) return 0;\n// if(arr[ind]==0) {\n// final_ans=1;\n// return dp[ind]=1;\n// }... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool dfs(vector<int>& arr, vector<bool>& vis, int index) {\n int n = arr.size();\n if (arr[index] == 0)\n return true;\n \n if(vis[index]==true) return false;\n \n vis[index]=true;\n \n \n if((index+arr... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool dfs(vector<int>& arr, vector<bool>& vis, int index) {\n int n = arr.size();\n if (arr[index] == 0)\n return true;\n\n if (vis[index] == true)\n return false;\n\n vis[index] = true;\n\n if ((index + arr[index]) < n ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n int n=arr.size();\n vector<int> adj[n+1];\n for(int i=0;i<n;i++){\n \n if(i-arr[i]>=0){\n int num=i-arr[i];\n adj[i].push_back(num);\n }\n ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n int n = arr.size();\n vector<int> adj[n];\n for(int i = 0; i < n; i++){\n if(i + arr[i] < n) adj[i].push_back(i+arr[i]);\n if(i - arr[i] >= 0) adj[i].push_back(i-arr[i]);\n }\n ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n int n = arr.size();\n vector<int> done(n);\n function<bool(int,int)> dfs = [&](int u, int p) {\n if(u<0 || u>=n || done[u]) return false;\n if(arr[u]==0) return true;\n done[u... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n int n = arr.size();\n vector<int> done(n);\n function<bool(int,int)> dfs = [&](int u, int p) {\n if(u<0 || u>=n || done[u]) return false;\n if(arr[u]==0) return true;\n done[u... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\n vector<bool> visited;\n vector<int> dp;\n int n;\npublic:\n bool helper(vector<int> &nums,int i) {\n if(i>=n or i<0) return false;\n if(visited[i]) return false;\n if(dp[i]!=-1) return dp[i];\n if(nums[i]==0) return dp[i] = true;\n visited[i... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\n vector<bool> visited;\n vector<int> dp;\n int n;\npublic:\n bool helper(vector<int> &nums,int i) {\n if(i>=n or i<0) return false;\n if(dp[i]!=-1) return dp[i];\n if(visited[i]) return false;\n if(nums[i]==0) return dp[i] = true;\n visited[i... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n int rec(vector<int>& arr, vector<int> &dp,int start,vector<bool> &vis){\n int n=arr.size();\n if(start<0||start>=n)\n return 0;\n if(arr[start]==0) return 1;\n if(vis[start]){\n return dp[start]!=-1?dp[start]:0;\n }\n ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\n\n void dfs(int i, bool &flag, vector<int>&arr, vector<bool>&vis)\n {\n \n vis[i] = true;\n if(arr[i] == 0)flag = true;\n\n if(i+arr[i] < arr.size() && !vis[i+arr[i]])\n dfs(i+arr[i], flag, arr, vis);\n\n if(i-arr[i] >= 0 && !vis[i-arr[i]])\... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool helper(vector<int>& arr,int s,unordered_map<int,int>& visited){\n \n if(s < 0 || s>= arr.size())\n return false;\n if(arr[s] == 0)\n return true;\n \n if(visited[s])\n re... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool helper(vector<int>& arr,int s,unordered_map<int,int>& visited){\n \n if(s < 0 || s>= arr.size())\n return false;\n if(arr[s] == 0)\n return true;\n \n if(visited[s])\n re... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n map<int, bool> visited;\n bool canReach(vector<int>& arr, int start) {\n if (start < 0 || start >= (int)arr.size()) {\n return false;\n }\n\n if (arr[start] == 0) {\n return true; \n }\n\n if (visited.count(start)... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& nums, int start)\n {\n return canJump(nums, start);\n }\n\nprivate:\n unordered_map<int, int> mp;\n bool canJump(vector<int>& nums, int index)\n {\n if (mp.find(index) != mp.end())\n return mp[index];\n\n ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n map<int,int> vis;\n bool canReach(vector<int>& arr, int start) {\n if(vis[start]==1){\n return false;\n }\n if(start<0||start>=arr.size()){\n return false;\n }\n if(arr[start]==0){\n return true;\n ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\nprivate:\n vector<bool> visited;\npublic:\n bool DFS(vector<int>& arr, int cur) {\n if (cur < 0 || cur >= arr.size()) {\n return false;\n }\n\n if (arr[cur] == 0) {\n return true;\n }\n\n if (visited[cur]) {\n retur... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n \n bool solve(vector<int>&arr, int idx,int n, vector<bool>&visited,vector<int>&dp){\n if(idx<0||idx>=n||visited[idx])return false;\n if(arr[idx]==0)return true;\n if(dp[idx]!=-1)return dp[idx];\n visited[idx]=true;\n bool ans=false;\n ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool DFS(vector<int>& visited, vector<int>& arr, int i) {\n if (i < 0 || i >= arr.size() || visited[i]) {\n return 0;\n }\n if (!arr[i]) {\n return 1;\n }\n\n visited[i] = 1;\n\n return DFS(visited, arr, i + arr[... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n set<int> visit;\n return helper(arr, start, visit);\n }\n\n bool helper(vector<int>& arr, int start, set<int>& visit) {\n if(start < 0 || start >= arr.size() || visit.contains(start)) return false;\n ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "\n\n\n\nclass Solution {\npublic:\n bool rx(std::vector<int> &nums, std::vector<bool> &visited, int i) {\n if(i >= nums.size() or i < 0 or visited[i]) { return false; }\n if(visited[i] or (nums[i] == 0)) { return true; }\n if(not visited[i]) {\n visited[i] = t... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n std::vector<bool> visited(arr.size());\n std::function<bool(int)> search = [&search, &arr, &visited](int i) -> bool {\n if(arr[i] == 0){\n return true;\n }\n auto ret ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "bool isValid(vector<int> &arr, int index, vector<bool> &visited)\n{\n return (index >= 0 && index < arr.size() && !visited[index]);\n}\n\nbool helper(vector<int> &arr, int start, vector<bool> &visited)\n{\n if(arr[start] == 0)\n {\n return true;\n }\n\n visited[start] = true;\n boo... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\n bool dfs(vector<int>& v , vector<bool>& vis, int start, int n) {\n if (v[start] == 0)\n return true;\n int a = v[start] + start;\n int b = start - v[start];\n bool a1 = false;\n if (a < n && !vis[a]){\n vis[a] = true;\n ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\nunordered_set<int>st;\n bool canReach(vector<int>& arr, int start) {\n if(st.count(start) || start<0 || start>=arr.size()) return false;\n if(arr[start]==0) return true;\n st.insert(start);\n return canReach(arr,start+arr[start]) || canReach(arr,sta... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n unordered_set<int> visited;\n bool rec(vector<int>& arr, int i) {\n if (visited.count(i) || i < 0 || i >= arr.size())\n return false;\n if (arr[i] == 0)\n return true;\n visited.insert(i);\n return rec(arr, i+arr[i]) || rec... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool solve(vector<int>&arr,int start,int n,unordered_set<int>&s)\n {\n if(start>=n)\n {\n return false;\n }\n if(start<0)\n {\n return false;\n }\n if(s.find(start)!=s.end())\n {\n ret... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "#include <vector>\n#include <unordered_set>\n#include <algorithm>\n\nclass Solution {\npublic:\n bool solve(const std::vector<int> &arr, const std::unordered_set<int> &target, int start, std::unordered_set<int> &visited) {\n // Check if the current index is out of bounds\n if (start < 0 ||... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\nprivate:\n unordered_set<int> memo;\n vector<int> arr;\n bool dfs(int idx){\n if(idx < 0 || idx >= this->arr.size() || this->memo.find(idx) != this->memo.end()) return false;\n if(this->arr[idx] == 0) return true;\n\n int val = this->arr[idx];\n this->... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n if(arr[start]==0) return true;\n int n=arr.size();\n vector<vector<int>> adj(n);\n for(int i=0;i<n;i++){\n if(i+arr[i]<n&&i+arr[i]>=0) adj[i].push_back(i+arr[i]);\n if(i-arr[i]<n&&i-a... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n vector<vector<int>> adj(arr.size());\n for (int idx = 0; idx < arr.size(); idx++) {\n int left = idx - arr[idx]; \n int right = idx + arr[idx]; \n \n if (left >= 0) {\n... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n vector<int> vist;\n void dfs(vector<int>& a,int at,vector<int> adj[]){\n vist[at] = 1;\n for(auto it: adj[at]){\n if(!vist[it]){\n dfs(a,it,adj);\n }\n }\n }\n bool canReach(vector<int>& a, int start) {\n ... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n set<int> st;\n vector<int> vis;\n // vector<int> adj[n];\n bool dfs(int node , vector<int> adj[] , vector<int>& arr){\n vis[node] = 1;\n // if(st.find(node) != st.end()) return true;\n if(arr[node]==0) return true;\n for(auto child : adj[n... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool canReach(vector<int>& arr, int start) {\n unordered_set<int> visited;\n\n return dfs(visited,arr,start);\n // if (visited.size() == arr.size()) return true;\n // return false;\n \n }\n bool dfs(unordered_set<int> &visited, vector<... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool solverecur(vector<int>& arr, int index, int final,unordered_map<int,bool>& visited) {\n if (index == final) {\n return true;\n }\n if(index<0)\n return false;\n if(index>=arr.size())\n return false;\n \n... |
1,428 | <p>Given an array of non-negative integers <code>arr</code>, you are initially positioned at <code>start</code> index of the array. When you are at index <code>i</code>, you can jump to <code>i + arr[i]</code> or <code>i - arr[i]</code>, check if you can reach <strong>any</strong> index with value 0.</p>... | 3 | {
"code": "class Solution {\npublic:\n bool solverecur(vector<int>& arr, int index, int final,unordered_map<int,bool>& visited) {\n if (index == final) {\n return true;\n }\n if(index<0)\n return false;\n if(index>=arr.size())\n return false;\n \n... |
1,435 | <p>You are given an array <code>arr</code> of positive integers. You are also given the array <code>queries</code> where <code>queries[i] = [left<sub>i, </sub>right<sub>i</sub>]</code>.</p>
<p>For each query <code>i</code> compute the <strong>XOR</strong> of elements from <code>left<sub>i</sub></code> to <code>right<s... | 0 | {
"code": "class Solution {\npublic:\n vector<int> xorQueries(vector<int>& arr, vector<vector<int>>& queries) {\n return {};\n }\n};\nbool init = ([]() -> char {\n ios::sync_with_stdio(false);\n ios_base::sync_with_stdio(false);\n ios::sync_with_stdio(false);\n cout.tie(nullptr);\n cin.tie... |
1,435 | <p>You are given an array <code>arr</code> of positive integers. You are also given the array <code>queries</code> where <code>queries[i] = [left<sub>i, </sub>right<sub>i</sub>]</code>.</p>
<p>For each query <code>i</code> compute the <strong>XOR</strong> of elements from <code>left<sub>i</sub></code> to <code>right<s... | 0 | {
"code": "class Solution {\npublic:\n vector<int> xorQueries(vector<int>& arr, vector<vector<int>>& queries) {\n return {};\n }\n};\nbool init = ([]() -> char {\n ios::sync_with_stdio(false);\n ios_base::sync_with_stdio(false);\n ios::sync_with_stdio(false);\n cout.tie(nullptr);\n cin.tie... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.