id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
463
<p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents&nbsp;land and <code>grid[i][j] = 0</code> represents water.</p> <p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded...
3
{ "code": "class Solution {\nprivate:\n bool isValid(int row, int col, int n, int m) {\n return (row < n) && (row >= 0) && (col < m) && (col >= 0);\n }\n void dfs(int row, int col, int n, int m, vector<vector<int>>& grid,\n vector<vector<bool>>& vis, vector<vector<int>>& sides,\n ...
463
<p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents&nbsp;land and <code>grid[i][j] = 0</code> represents water.</p> <p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded...
3
{ "code": "class Solution {\npublic:\n int islandPerimeter(vector<vector<int>>& grid) {\n int row= grid.size();\n int col= grid[0].size();\n int perimeter=0;\n\n for(int i=0; i<row; i++){\n for(int j=0; j<col; j++){\n if(grid[i][j]==1){\n\n vector<pair<int, int>>direc...
463
<p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents&nbsp;land and <code>grid[i][j] = 0</code> represents water.</p> <p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded...
3
{ "code": "class Solution {\npublic:\nvoid dfs(vector<vector<int>>& grid, int x, int y,int &ans) {\n vector<pair<int, int>> directions = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};\n // res.push_back({x, y});\n grid[x][y]=2;\n int count=0;\n for (auto& dir : directions) {\n int n...
463
<p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents&nbsp;land and <code>grid[i][j] = 0</code> represents water.</p> <p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded...
3
{ "code": "class Solution {\npublic:\n int bfs(int i,int j,vector<vector<int>>& v,vector<vector<int>> vis){\n int n=v.size(),m=v[0].size();\n queue<pair<int,int>> q;\n q.push({i,j});\n vis[i][j]=1;\n int ans=0;\n while(q.size()){\n int x=q.front().first;\n ...
463
<p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents&nbsp;land and <code>grid[i][j] = 0</code> represents water.</p> <p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded...
3
{ "code": "class Solution {\npublic:\n int islandPerimeter(vector<vector<int>>& grid) {\n std::set<std::pair<int, int>> visited;\n int p = 0;\n int rows = grid.size();\n int cols = grid[0].size();\n\n for (int i = 0; i < rows; ++i) {\n for (int j = 0; j < cols; ++j) {\...
463
<p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents&nbsp;land and <code>grid[i][j] = 0</code> represents water.</p> <p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded...
3
{ "code": "class Solution {\nprivate:\n void dfs(int r, int c, vector<vector<int>>& grid, vector<vector<int>> &vis,\n map<pair<int, int>, int> &sides, int rows, int cols) {\n vis[r][c] = 1;\n\n int delRow[] = {-1,0,1,0};\n int delCol[] = {0,-1,0,1};\n for(int i=0; i<4; i++) {...
463
<p>You are given <code>row x col</code> <code>grid</code> representing a map where <code>grid[i][j] = 1</code> represents&nbsp;land and <code>grid[i][j] = 0</code> represents water.</p> <p>Grid cells are connected <strong>horizontally/vertically</strong> (not diagonally). The <code>grid</code> is completely surrounded...
3
{ "code": "class Solution {\npublic:\n int rows;\n int cols;\n vector<pair<int,int>> directions = {{-1,0}, {1,0}, {0,-1}, {0,1}};\n\n bool valid( int row, int col ){\n return row >= 0 && row < rows && col >= 0 && col < cols;\n }\n\n int countSides( int row, int col, vector<vector<int>>& grid)...
1,297
<p>Given a string <code>text</code>, you want to use the characters of <code>text</code> to form as many instances of the word <strong>&quot;balloon&quot;</strong> as possible.</p> <p>You can use each character in <code>text</code> <strong>at most once</strong>. Return the maximum number of instances that can be forme...
0
{ "code": "class Solution {\npublic:\n/*\ncreate a vector that has the bins of each letter\n\niterate across this to find the minimum value\n\nhave an output that is the minimum value\n*/\n int maxNumberOfBalloons(string text) {\n int maxNumberOfBalloonss = (std::count(text.begin(), text.end(), 'b'));\n ...
1,297
<p>Given a string <code>text</code>, you want to use the characters of <code>text</code> to form as many instances of the word <strong>&quot;balloon&quot;</strong> as possible.</p> <p>You can use each character in <code>text</code> <strong>at most once</strong>. Return the maximum number of instances that can be forme...
0
{ "code": "class Solution {\npublic:\n int maxNumberOfBalloons(string text) {\n int arr[26] = {};\n for (auto c : text) arr[c - 'a']++;\n auto & b = arr['b' - 'a'];\n auto & a = arr['a' - 'a'];\n auto & l = arr['l' - 'a'];\n auto & o = arr['o' - 'a'];\n auto & n = a...
1,297
<p>Given a string <code>text</code>, you want to use the characters of <code>text</code> to form as many instances of the word <strong>&quot;balloon&quot;</strong> as possible.</p> <p>You can use each character in <code>text</code> <strong>at most once</strong>. Return the maximum number of instances that can be forme...
0
{ "code": "class Solution {\n public:\n int maxNumberOfBalloons(string text) {\n int ans = INT_MAX;\n vector<int> count(26);\n\n for (char c : text)\n ++count[c - 'a'];\n\n for (char c : string(\"ban\"))\n ans = min(ans, count[c - 'a']);\n\n for (char c : string(\"lo\"))\n ans = min(ans...
1,297
<p>Given a string <code>text</code>, you want to use the characters of <code>text</code> to form as many instances of the word <strong>&quot;balloon&quot;</strong> as possible.</p> <p>You can use each character in <code>text</code> <strong>at most once</strong>. Return the maximum number of instances that can be forme...
0
{ "code": "class Solution {\npublic:\n int maxNumberOfBalloons(string text) {\n vector<int> count(26,0);\n for(auto x: text)\n {\n count[x - 'a']++;\n }\n\n count['l' - 'a'] /= 2;\n count['o' - 'a'] /= 2;\n string balloon = \"balon\";\n int min_bal...
1,297
<p>Given a string <code>text</code>, you want to use the characters of <code>text</code> to form as many instances of the word <strong>&quot;balloon&quot;</strong> as possible.</p> <p>You can use each character in <code>text</code> <strong>at most once</strong>. Return the maximum number of instances that can be forme...
0
{ "code": "class Solution {\npublic:\n int maxNumberOfBalloons(string text) {\n int letters[27];\n int ans = 0;\n\n for (char c : text) {\n letters[c - 'a'] += 1;\n }\n\n while (true) {\n letters['b' - 'a'] -= 1;\n letters['a' - 'a'] -= 1;\n ...
1,297
<p>Given a string <code>text</code>, you want to use the characters of <code>text</code> to form as many instances of the word <strong>&quot;balloon&quot;</strong> as possible.</p> <p>You can use each character in <code>text</code> <strong>at most once</strong>. Return the maximum number of instances that can be forme...
0
{ "code": "class Solution {\npublic:\n int maxNumberOfBalloons(string text) {\n string targetWord = \"balon\";\n vector<pair<char, size_t>> letters;\n for ( char letter : targetWord )\n letters.push_back(make_pair(letter, 0));\n\n for ( char letter : text ) {\n thi...
1,297
<p>Given a string <code>text</code>, you want to use the characters of <code>text</code> to form as many instances of the word <strong>&quot;balloon&quot;</strong> as possible.</p> <p>You can use each character in <code>text</code> <strong>at most once</strong>. Return the maximum number of instances that can be forme...
0
{ "code": "class Solution {\npublic:\n int maxNumberOfBalloons(string text) {\n// string s = {\"ablloon\"};\n// sort(begin(text), end(text));\n// int cnt = 0;\n// for(int i =0 ;i<size(text);i++){\n// if(s[i] == text[i]){\n// if(i == size(s)-1 && i!= size(...
1,297
<p>Given a string <code>text</code>, you want to use the characters of <code>text</code> to form as many instances of the word <strong>&quot;balloon&quot;</strong> as possible.</p> <p>You can use each character in <code>text</code> <strong>at most once</strong>. Return the maximum number of instances that can be forme...
1
{ "code": "class Solution {\npublic:\n int maxNumberOfBalloons(string s) \n {\n string target = \"balloon\";\n\n vector<int>v1(26,0);\n for(int i=0;i<target.length();i++)\n {\n char ch = target[i];\n v1[ch-'a']++;\n }\n vector<int>v2(26,0);\n ...
1,297
<p>Given a string <code>text</code>, you want to use the characters of <code>text</code> to form as many instances of the word <strong>&quot;balloon&quot;</strong> as possible.</p> <p>You can use each character in <code>text</code> <strong>at most once</strong>. Return the maximum number of instances that can be forme...
1
{ "code": "class Solution {\npublic:\n int maxNumberOfBalloons(string text) {\n string balloon = \"balloon\";\n int count = 0;\n \n while (true) {\n string sample = \"\";\n for (int i = 0; i < balloon.size(); i++) {\n size_t pos = text.find(balloon[i...
1,297
<p>Given a string <code>text</code>, you want to use the characters of <code>text</code> to form as many instances of the word <strong>&quot;balloon&quot;</strong> as possible.</p> <p>You can use each character in <code>text</code> <strong>at most once</strong>. Return the maximum number of instances that can be forme...
1
{ "code": "class Solution {\npublic:\n int countt (string s, char c) {\n return count (s.begin(), s.end(), c);\n }\n int maxNumberOfBalloons(string s) {\n int b = countt (s, 'b');\n int a = countt (s, 'a');\n int l = countt (s, 'l') / 2;\n int o = countt (s, 'o') / 2;\n ...
1,297
<p>Given a string <code>text</code>, you want to use the characters of <code>text</code> to form as many instances of the word <strong>&quot;balloon&quot;</strong> as possible.</p> <p>You can use each character in <code>text</code> <strong>at most once</strong>. Return the maximum number of instances that can be forme...
1
{ "code": "class Solution {\npublic:\n int maxNumberOfBalloons(string text) {\n unordered_map<char,int> counter;\n string balloon=\"balloon\";\n\n for(char ch:text){\n if(balloon.find(ch) != string :: npos){\n counter[ch]++;\n }\n }\n\n if(co...
1,297
<p>Given a string <code>text</code>, you want to use the characters of <code>text</code> to form as many instances of the word <strong>&quot;balloon&quot;</strong> as possible.</p> <p>You can use each character in <code>text</code> <strong>at most once</strong>. Return the maximum number of instances that can be forme...
1
{ "code": "class Solution {\npublic:\n int maxNumberOfBalloons(string text) {\n unordered_map <char,int> mp;\n for(auto x:text){\n if(x=='a'||x=='b'||x=='l'||x=='o'||x=='n')\n mp[x]++;\n }\n return min({mp['b'], mp['a'], mp['l']/2, mp['o']/2, mp['n']});\n }\n ...
1,297
<p>Given a string <code>text</code>, you want to use the characters of <code>text</code> to form as many instances of the word <strong>&quot;balloon&quot;</strong> as possible.</p> <p>You can use each character in <code>text</code> <strong>at most once</strong>. Return the maximum number of instances that can be forme...
1
{ "code": "class Solution {\npublic:\n int maxNumberOfBalloons(string text) {\n std:map<char,int> occurs;\n occurs['b']=0;\n occurs['a']=0;\n occurs['l']=0;\n occurs['l']=0;\n occurs['o']=0;\n occurs['o']=0;\n occurs['n']=0;\n\n for(auto& ch:text)\n ...
1,297
<p>Given a string <code>text</code>, you want to use the characters of <code>text</code> to form as many instances of the word <strong>&quot;balloon&quot;</strong> as possible.</p> <p>You can use each character in <code>text</code> <strong>at most once</strong>. Return the maximum number of instances that can be forme...
1
{ "code": "class Solution {\npublic:\n int maxNumberOfBalloons(string text) {\n int n = text.size();\n unordered_map<char,int>mpp;\n for(auto c:text){\n mpp[c]++;\n }\n\n int mini = INT_MAX;\n //{ b-1, a-1 , l-2, o-2 , n-1 }\n mini = min(mpp['b'],min(mpp[...
1,297
<p>Given a string <code>text</code>, you want to use the characters of <code>text</code> to form as many instances of the word <strong>&quot;balloon&quot;</strong> as possible.</p> <p>You can use each character in <code>text</code> <strong>at most once</strong>. Return the maximum number of instances that can be forme...
1
{ "code": "class Solution {\npublic:\n // TC = O(N)\n // SC = O(1)\n int maxNumberOfBalloons(string text) {\n\n unordered_map<char,int>freq;\n\n for(char ch : text){\n if(ch =='b' || ch =='a' || ch =='l' || ch =='o' || ch =='n'){\n freq[ch]++;\n }\n }...
1,297
<p>Given a string <code>text</code>, you want to use the characters of <code>text</code> to form as many instances of the word <strong>&quot;balloon&quot;</strong> as possible.</p> <p>You can use each character in <code>text</code> <strong>at most once</strong>. Return the maximum number of instances that can be forme...
2
{ "code": "class Solution {\npublic:\n int maxNumberOfBalloons(string text) {\n unordered_map<char,int>mp1;\n unordered_map<char,int>mp2;\n int count=INT_MAX;\n string ss=\"balloon\";\n for(int i=0;i<text.size();i++){\n mp1[text[i]]++;\n }\n fo...
1,297
<p>Given a string <code>text</code>, you want to use the characters of <code>text</code> to form as many instances of the word <strong>&quot;balloon&quot;</strong> as possible.</p> <p>You can use each character in <code>text</code> <strong>at most once</strong>. Return the maximum number of instances that can be forme...
2
{ "code": "class Solution {\npublic:\n int maxNumberOfBalloons(string text) {\n std:map<char,int> occurs;\n occurs['b']=0;\n occurs['a']=0;\n occurs['l']=0;\n occurs['l']=0;\n occurs['o']=0;\n occurs['o']=0;\n occurs['n']=0;\n\n for(auto& ch:text)\n ...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
0
{ "code": "class Solution {\npublic:\n long long subArrayRanges(vector<int>& nums) {\n long long ans=0;\n for(int i=0;i<nums.size();i++)\n {long long maxi=INT_MIN;\n long long mini=INT_MAX;\n maxi=max(maxi,nums[i]+0LL);\n mini=min(mini,nums[i]+0LL);\n for(int ...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
0
{ "code": "class Solution {\npublic:\n long long subArrayRanges(vector<int>& arr) {\n long long ans=0;\n int n=arr.size();\n\n for(int i=0;i<n;i++){\n int Min=arr[i];\n int Max=arr[i];\n for(int j=i+1;j<n;j++){\n Min=min(Min,arr[j]);\n ...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
0
{ "code": "class Solution {\npublic:\n long long subArrayRanges(vector<int>& nums) {\n int mini=-1;\n int maxi=-1;\n int n=nums.size();\n long long s=0;\n for(int i=0;i<n;i++){\n maxi=nums[i];\n mini=nums[i];\n for(int j=i+1;j<n;j++){\n ...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
0
{ "code": "class Solution {\npublic:\n long long subArrayRanges(vector<int>& nums) {\n long long res =0;\n int n=nums.size();\n for(int i=0;i<n;i++){\n long long mn = nums[i];\n long long mx = nums[i];\n for(int j=i+1;j<n;j++){\n // mn = min(mn,...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
0
{ "code": "class Solution {\npublic:\n long long subArrayRanges(vector<int>& nums) {\n long long int sum = 0;\n int n = nums.size();\n\n for(int i=0 ; i<n ; i++){\n int largest = nums[i];\n int smallest = nums[i];\n for(int j=i+1 ; j<n ; j++){\n ...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
0
{ "code": "class Solution {\npublic:\n long long subArrayRanges(vector<int>& nums) {\n int n=nums.size();\n long long ans=0;\n for(int i=0;i<n;i++){\n int maxi=nums[i];\n int mini=nums[i];\n for(int j=i;j<n;j++){\n ...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
0
{ "code": "class Solution {\npublic:\n long long subArrayRanges(vector<int>& nums) {\n int n=nums.size();\n long ans=0;\n for(int i=0;i<n;i++)\n {\n int minV=nums[i];\n int maxV=nums[i];\n for(int j=i;j<n;j++)\n {\n maxV=max(max...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
0
{ "code": "class Solution {\npublic:\n long long subArrayRanges(vector<int>& nums) {\n int n = nums.size();\n long long res = 0;\n\n for(int i=0; i<n-1; i++)\n {\n int maxi = nums[i], mini = nums[i];\n\n for(int j=i+1; j<n; j++)\n {\n if(n...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
0
{ "code": "class Solution {\npublic:\n long long subArrayRanges(vector<int>& nums) {\n long long ans = 0;\n for(int i=0; i<nums.size(); i++){\n int mini = nums[i];\n int maxi = nums[i];\n for(int j=i+1; j<nums.size(); j++){\n mini = min(mini, nums[j]);\...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
1
{ "code": "class Solution {\npublic:\n\n void findNSE(vector<int>& arr, int dir, int *res){\n // dir == 0 for left and 1 for right;\n int n = arr.size();\n stack <int> st;\n if(dir==0){\n for(int i=0; i<n; i++){\n while(!st.empty() && arr[st.top()] > arr[i])\n...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
1
{ "code": "class Solution {\npublic:\n long long subarraymaxi(vector<int>& arr)\n {\n int n=arr.size();\n long long pge[n];\n long long nge[n];\n stack<long long> st;\n for(int i=0;i<n;i++)\n {\n while(!st.empty()&&arr[i]>arr[st.top()])\n {\n ...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
1
{ "code": "class Solution {\npublic:\n long long subArrayRanges(vector<int>& nums) {\n stack<int>maxi ;\n \n \n vector<int>nextsmaller(nums.size(),-1) ;\n for (int i = nextsmaller.size()-1 ; i >= 0 ; i-- ){\n while(!maxi.empty() && nums[maxi.top()] >= nums[i] ){\n maxi.pop();\n }\n if (...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
1
{ "code": "class Solution {\npublic:\n long long subArrayRanges(vector<int>& nums) {\n int n = nums.size();\n vector<int>nle(n,n),nge(n,n);\n stack<int>st1,st2;\n\n long long dp1[n+1], dp2[n+1], ans=0;\n dp1[n]=dp2[n]=0;\n\n for(int i=n-1;i>=0;i--){\n while(!st1...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
1
{ "code": "class Solution {\npublic:\n long long subArrayRanges(vector<int>& arr) {\n\n int n = arr.size();\n\n // find next smaller on next and right side\n\n vector<int> left_smaller(n, -1);\n\n vector<int> right_smaller(n, n);\n\n stack<int> st;\n\n // fill left_smaller...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
1
{ "code": "class Solution {\npublic:\n \n long long subArrayRanges(vector<int>& nums) {\n int n=nums.size();\n long long sum=0;\n stack<int>st;\n vector<int> minPrev(n,-1),minNext(n,n),maxPrev(n,-1),maxNext(n,n);\n \n for(int i=0;i<n;i++)\n {\n while(!...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
1
{ "code": "class Solution {\npublic:\n \n long long subArrayRanges(vector<int>& nums) {\n int n=nums.size();\n long long sum=0;\n stack<int>st;\n vector<int> minPrev(n,-1),minNext(n,n),maxPrev(n,-1),maxNext(n,n);\n \n for(int i=0;i<n;i++)\n {\n while(!...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
1
{ "code": "class Solution {\npublic:\n \n long long subArrayRanges(vector<int>& nums) {\n int n=nums.size();\n long long sum=0;\n stack<int>st;\n vector<int> minPrev(n,-1),minNext(n,n),maxPrev(n,-1),maxNext(n,n);\n \n for(int i=0;i<n;i++)\n {\n while(!...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
1
{ "code": "class Solution {\npublic:\n long long subArrayRanges(vector<int>& nums) {\n int n = nums.size();\n vector<int> next_max(n, n);\n vector<int> prev_max(n, -1);\n vector<int> next_min(n, n);\n vector<int> prev_min(n, -1);\n\n stack<int> s;\n\n for (int i = 0...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
2
{ "code": "class Solution {\n\nprivate:\n vector<int> computeNextSmaller(vector<int>& arr) {\n int n = arr.size();\n stack<int> st;\n vector<int> nse(n);\n for (int i=n-1; i>=0; i--) {\n while (!st.empty() && arr[st.top()]>=arr[i]) {\n st.pop();\n }\...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
2
{ "code": "class Solution {\npublic:\nvector<int> findNSE(vector<int>& nums) {\n int n = nums.size();\n vector<int> nse(n);\n stack<int> st;\n for(int i=n-1; i>=0; i--) {\n while(!st.empty() && nums[st.top()] >= nums[i])\n st.pop();\n nse[i] = st.empty(...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
2
{ "code": "class Solution {\npublic:\n void findNSE(vector<int>& arr, vector<int>& nse, int n) {\n stack<int>st;\n for(int i = n - 1;i >= 0;i--) {\n while(!st.empty() && arr[st.top()] >= arr[i]) {\n st.pop();\n }\n nse[i] = st.empty() ? n : st.top();\n ...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
2
{ "code": "class Solution {\npublic:\nvector<int> findNSE(vector<int>& nums) {\n int n = nums.size();\n vector<int> nse(n);\n stack<int> st;\n for(int i=n-1; i>=0; i--) {\n while(!st.empty() && nums[st.top()] >= nums[i])\n st.pop();\n nse[i] = st.empty(...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
3
{ "code": "class Solution {\npublic:\n vector<int> findNSE(vector<int>& arr) {\n int n = arr.size();\n stack<int> st;\n vector<int> nse(n);\n for (int i = n - 1; i >= 0; i--) {\n while (!st.empty() && arr[st.top()] >= arr[i]) st.pop();\n nse[i] = st.empty() ? n : s...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
3
{ "code": "class Solution {\npublic:\n long long subArrayRanges(vector<int>& arr) {\n //BRUTE FORCE TC=O(N^2) SC=O(1)\n //Going through all SubArrays\n /*\n int mini,maxi;\n int n=arr.size();\n long long ans=0;\n for(int i=0;i<n;i++)\n {\n mini...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
3
{ "code": "class Solution {\n vector<int> findNSE(vector<int>& nums) {\n int n = nums.size();\n vector<int> nse(n);\n stack<int> st;\n for(int i=n-1; i>=0; i--) {\n while(!st.empty() && nums[st.top()] >= nums[i])\n st.pop();\n nse[i] = st.empty() ? ...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
3
{ "code": "class Solution {\npublic:\n vector<int> nslCalc(vector<int>& arr) {\n vector<int> nsl(arr.size(), -1);\n stack<int> s;\n\n for(int i = 0; i < arr.size(); i++){\n while(!s.empty() && arr[s.top()] > arr[i]){\n s.pop();\n }\n\n nsl[i] = s...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
3
{ "code": "class Solution {\npublic:\n long long sumSubarrayMins(vector<int>& arr) {\n int n = arr.size();\n long long res = 0;\n vector<long long> left(n,-1),right(n,n);\n stack<long long> st;\n for(int i=0;i<n;i++){\n while(!st.empty() && arr[st.top()] >= arr[i]) st....
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
3
{ "code": "class Solution {\npublic:\n vector<int>PS(vector<int>arr){\n int n=arr.size();\n stack<int>st;\n st.push(-1);\n vector<int>ans(n);\n for(int i=0;i<n;i++){\n while(st.size()>1 && arr[st.top()]>arr[i]){\n st.pop();\n }\n ...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
3
{ "code": "class Solution {\npublic:\n ;\n long long solve2(vector<int>& arr) {\n vector<long long>v(arr.size(),0);\n stack<int>st;\n long long ans=0;\n int n=arr.size();\n v[n-1]=n;\n st.push(n-1);\n for(int i=n-2;i>=0;i--){\n while(!st.empty() && arr...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
3
{ "code": "class Solution {\npublic:\n\nvector<int> PGE(vector<int> a)\n{\n int n=a.size();\n stack<int> s;\n vector<int> pge(n);\n for(int i=0;i<n;i++)\n {\n while(!s.empty() && a[s.top()]<=a[i])\n {\n s.pop();\n }\n pge[i]=s.empty()?-1:s.top();\n s.push(i...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
3
{ "code": "class Solution {\npublic:\nvector<int>findnse(vector<int>&arr){\n int n=arr.size();\n vector<int>nse(n);\n stack<int>st;\n for(int i=n-1;i>=0;i--){\n while(!st.empty()&&arr[st.top()]>=arr[i]){\n st.pop();\n\n }\n nse[i]=st.empty()?n:st.top();\n st.push(i);...
2,227
<p>You are given an integer array <code>nums</code>. The <strong>range</strong> of a subarray of <code>nums</code> is the difference between the largest and smallest element in the subarray.</p> <p>Return <em>the <strong>sum of all</strong> subarray ranges of </em><code>nums</code><em>.</em></p> <p>A subarray is a co...
3
{ "code": "class Solution {\n long long amin(vector<int>& arr){\n int n = arr.size();\n stack<long long>s1,s2;\n vector<long long>left(n),right(n);\n long long ans=0;\n\n for(int i=0;i<n;i++){\n right[i]=n-i-1;\n left[i]=i;\n }\n\n for(int i=0;i<n;i++){\...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
0
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) {\n for(auto& word : words){\n if(isPalin(word)) {\n return word;\n }\n }\n return \"\";\n }\n bool isPalin(string& word){\n int i = 0, j = word.size()-1;\n ...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
0
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) {\n bool flag=true;\n string word=\"\";\n for(int i=0;i<words.size();i++){\n bool flag=true;\n for(int j=0;j<= words[i].size()/2;j++){\n if(words[i][j]!=words[i][words[i].s...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
0
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) {\n for (string const& s : words) {\n if (is_palindrome(s)) {return s;}\n }\n return {};\n }\n\n bool is_palindrome(string_view v) {\n int i{0}, j{static_cast<int>(v.size()) - 1};\n ...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
0
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) {\n for (string const& s : words) {\n if (is_palindrome(s)) {return s;}\n }\n return {};\n }\n\n bool is_palindrome(string_view v) {\n int i{0}, j{static_cast<int>(v.size()) - 1};\n ...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
0
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) {\n for(int i=0;i<words.size();i++)\n {\n int l=0,h = words[i].length()-1;\n bool ch = false;\n while(l<h)\n {\n if(words[i][l] == words[i][h])\n ...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
1
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) {\n string t=\"\";\n for(int i=0; i<words.size(); i++){\n t=words[i];\n reverse(t.begin(), t.end());\n if(words[i][0]==words[i][words[i].size()-1]){\n if(t==words[i])\n...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
1
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) {\n for(int i = 0; i < words.size(); ++i){\n int l = 0, r = words[i].size() - 1;\n int checker = 1;\n while(l<=r){\n if(words[i][l] != words[i][r]){\n check...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
1
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) {\n string str=\"\";\n for(int i=0; i<words.size(); i++){\n str=words[i];\n bool flag=true;\n int m=0,n=str.length()-1;\n while(m<n){\n if(str[m]!= str[n]){\...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
1
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) {\n vector<string> ans;\n int n=words.size();\n string s=\"\";\n for(int i=0;i<n;i++){\n s=words[i];\n reverse(s.begin(),s.end());\n if(s==words[i]){\n re...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
1
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) {\n for(int i=0;i<words.size();i++)\n {\n int size = words[i].size();\n if(words[i][0]==words[i][size-1])\n {\n string word = words[i];\n int k = 0;\n int l = word.size()...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
1
{ "code": "class Solution {\npublic:\n bool ispalindrome(string s)\n {\n int i=0;\n int j = s.size()-1;\n while(i<=j)\n {\n if(s[i]!=s[j])return false;\n i++;\n j--;\n }\n return true;\n }\n string firstPalindrome(vector<string>& w...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
1
{ "code": "class Solution {\npublic:\n bool checker(string s){\n int l = 0;\n int r = s.size() - 1;\n\n while(l<=r){\n if(s[l] != s[r]){\n return false;\n }\n l++;\n r--;\n }\n ...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
1
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) {\n for(string s : words){\n if(peli(0, s.size(), s)){\n return s;\n }\n }\n return \"\";\n }\n\nprivate:\n bool peli(int i, int n, const string& s){\n if(i>=...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
1
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) {\n for (string& word : words)\n {\n string reversed = word;\n reverse(reversed.begin(), reversed.end());\n if (reversed == word) return word;\n }\n return \"\";\n }\...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
1
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) {\n for(string s : words){\n if(peli(0, s.size(), s)){\n return s;\n }\n }\n return \"\";\n }\n\nprivate:\n bool peli(int i, int n, const string& s){\n if(i>=...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
1
{ "code": "class Solution {\npublic:\n\n bool isPalin(string &s){\n int st=0, en=s.size()-1;\n\n while(st<en){\n if(s[st]!=s[en]) return false;\n st++;\n en--;\n }\n\n return true;\n }\n\n string firstPalindrome(vector<string>& words) {\n fo...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
2
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) {\n \n for(int i = 0; i < words.size(); i++){\n string curr = words[i];\n reverse(curr.begin(), curr.end());\n if(words[i] == curr){\n return words[i];\n }\n...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
2
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) \n {\n for(int i=0;i<words.size();i++)\n {\n string res=words[i];\n reverse(res.begin(),res.end());\n if(res==words[i])\n {\n return ...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
2
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) {\n string s=\"\";\n for(auto it: words)\n {\n s=it;\n reverse(s.begin(),s.end());\n if(it==s)\n {\n return s;\n }\n }\n s=\"...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
2
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) {\n string ans;\n string check;\n stack<int>s;\n\n\n for(int i=0;i<words.size();i++)\n {\n string temp=words[i];\n reverse(words[i].begin(),words[i].end());\n if(...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
2
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) {\n for (const string& word : words) {\n if (word == string(word.rbegin(), word.rend())) {\n return word;\n }\n }\n return \"\";\n }\n};", "memory": "27800" }
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
2
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) {\n for(string &word : words)\n {\n if(word == string(rbegin(word), rend(word)))\n {\n return word;\n }\n }\n return \"\";\n }\n};", "memory": "27900...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
2
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) {\n for(int i=0; i<words.size(); i++){\n if(words[i]== string(words[i].rbegin(), words[i].rend())){\n return words[i];\n }\n }\n return \"\";\n }\n};", "memory": "2800...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
2
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) \n {\n vector<string> grid=words;\n\n for(int i=0;i<words.size();i++)\n {\n reverse(words[i].begin(),words[i].end());\n if(words[i]==grid[i])\n return words[i];\n } ...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
2
{ "code": "class Solution {\npublic:\n\n bool check_palindrome(string &strInput) {\n int halfway = (strInput.length() / 2);\n int full_length = strInput.length() - 1;\n int i = 0;\n bool isPalindrome = true;\n while (i <= halfway) {\n // cout<<\"i-th letter is \"<<strI...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
2
{ "code": "class Solution {\npublic:\n Solution() { ios_base::sync_with_stdio(false); cin.tie(NULL); }\n \n auto firstPalindrome(vector<string> words) -> string{\n auto const& result = find_if(cbegin(words), cend(words), [](auto const &word){\n return equal(cbegin(word), cbegin(word) + size(word)...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
2
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string> words) {\n for (const auto& word : words) {\n if (isPalindrome(word)) {\n return word;\n }\n }\n return \"\";\n }\n\nprivate:\n bool isPalindrome(const std::string& str) {\n ...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
2
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) {\n queue<string> st(words.begin(), words.end());\n \n string s = \"\";\n for(int i=0; i<words.size(); i++){\n reverse(words[i].begin(), words[i].end());\n if(words[i] == st.front(...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
2
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) {\n queue<string> st(words.begin(), words.end());\n \n string s = \"\";\n for(int i=0; i<words.size(); i++){\n reverse(words[i].begin(), words[i].end());\n if(words[i] == st.front(...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
2
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) {\n int n = words.size();\n for(int i=0; i<n; i++){\n string x = words[i];\n if(x[0]==x[x.length()-1]){\n string y = x;\n reverse(x.begin(),x.end());\n ...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
2
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) {\n int n = words.size();\n for(int i=0; i<n; i++){\n string x = words[i];\n if(x[0]==x[x.length()-1]){\n string y = x;\n reverse(x.begin(),x.end());\n ...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
2
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) {\n for(int i = 0; i < words.size(); i++){\n int l = 0, r = words[i].length() - 1;\n string str1, str2;\n while(l < r){\n str1.push_back(words[i][l++]);\n str2....
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
2
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) {\n vector<string> n;\n for(int i=0;i<words.size();i++){\n n.push_back(words[i]);\n }\n for(int i=0;i<words.size();i++){\n reverse(words[i].begin(),words[i].end());\n }\n ...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
2
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) {\n string ans;\n vector<string> s;\n for(int i =0;i<size(words);i++)\n {\n s.push_back(words[i]);\n reverse(words[i].begin(),words[i].end());\n \n } \n for(i...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
2
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) {\n\n int n=words.size();\n string s;\n string ans;\n vector<string> v;\n for(int i=0;i<n;i++){\n s=words[i];\n reverse(s.begin(),s.end());\n v.push_back(s);\n }\n\n ...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
2
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) {\n\n int n=words.size();\n string s;\n string ans;\n vector<string> v;\n for(int i=0;i<n;i++){\n s=words[i];\n reverse(s.begin(),s.end());\n v.push_back(s);\n }\n\n ...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
2
{ "code": "class Solution {\n bool ispalindrom(string s)\n {\n bool b = true;\n int n = s.size();\n for(int i = 0; i < n / 2; ++i)\n b &= (s[i] == s[n - i - 1]);\n return b;\n }\npublic:\n string firstPalindrome(vector<string>& words) {\n for(string s : words)...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
2
{ "code": "class Solution {\npublic:\n bool isPalindrome(string s){\n int n = s.size();\n int i = 0;\n while(i<n/2){\n\n if(s[i] != s[n-i-1]) return false;\n i++;\n }\n\n return true;\n }\n string firstPalindrome(vector<string>& words) {\n \n ...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
2
{ "code": "class Solution {\npublic:\n bool isPalindrome(string s){\n int l = 0, r = s.size()-1;\n while(r >= l){\n if (s[r] != s[l]){\n return false;\n }\n\n l++;\n r--;\n }\n\n return true;\n }\n string firstPalindrome(v...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
3
{ "code": "class Solution {\npublic:\nbool ispalindromic(string s ){\n int left = 0 ; \n int right = s.size() - 1 ;\n while( left < right ){\n if(s[left] != s[right]){\n return false ;\n }\n left++;\n right--;\n }\n return true;\n}\n string firstPalindrome(vect...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
3
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) {\n for(auto ss : words){\n string answer = ss;\n int l = 0;\n int r = ss.size() - 1;\n bool isPalindrome = true;\n \n while(l <= r){\n if(ss[l] != ss[r]){\n i...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
3
{ "code": "class Solution {\npublic:\n bool check(string word){\n int i=0,j=word.size()-1;\n while(i<j){\n if(word[i]!=word[j])\n return false;\n i++;\n j--;\n }\n return true;\n }\n string firstPalindrome(vector<string>& words) {\n ...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
3
{ "code": "class Solution {\npublic:\n string firstPalindrome(vector<string>& words) {\n int idx =0; \n int n= words.size();\n for(auto i:words){\n string s =i;\n reverse(s.begin(), s.end());\n if(s==i){\n return s;\n }\n }\n ...
2,231
<p>Given an array of strings <code>words</code>, return <em>the first <strong>palindromic</strong> string in the array</em>. If there is no such string, return <em>an <strong>empty string</strong> </em><code>&quot;&quot;</code>.</p> <p>A string is <strong>palindromic</strong> if it reads the same forward and backward....
3
{ "code": "class Solution {\n\n bool isPalindrome(string word){\n int st = 0;\n int end = word.length() - 1;\n\n while(st<end){\n if(word[st] != word[end]){\n return 0;\n }\n st++;\n end--;\n }\n return 1;\n }\n\npubli...