id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 2 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n\n string l;\n for(int i=0;i<s.length();i++)\n {\n if(s[i]!='-')\n {\n l.push_back(toupper(s[i]));\n }\n }\n reverse(l.begin(),l.end());\n ... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 2 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n\n string l;\n for(int i=0;i<s.length();i++)\n {\n if(s[i]!='-')\n {\n l.push_back(toupper(s[i]));\n }\n }\n reverse(l.begin(),l.end());\n ... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 3 | {
"code": "class Solution {\n public:\n string licenseKeyFormatting(string s, int k) {\n\n string l;\n for(int i=0;i<s.length();i++)\n {\n if(s[i]!='-')\n ... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 3 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n string temp =\"\";\n string proto = \"\";\n string ans =\"\";\n for(auto it: s){\n if(it!='-'){\n temp+= toupper(it);\n }\n else {\n pro... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 3 | {
"code": "class Solution {\npublic:\n string upper(string s)\n {\n \n for(int i=0;i<s.size();i++)\n {\n if(s[i]>='a' and s[i]<='z')\n {\n s[i] = s[i] - 'a'+ 'A'; \n }\n }\n return s;\n }\n string remove(string s)\n {\n ... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 3 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n string justalphanum;\n string res;\n for(int i=0;i<s.size();i++){\n if(!isalnum(s[i])){\n continue;\n }\n justalphanum.push_back(s[i]);\n\n }\n\n string upperal;\n f... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 3 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n string licenceWithoutDash = \"\";\n for(auto c : s) {\n if(c != '-')\n licenceWithoutDash.push_back(toupper(c));\n }\n string currWord = \"\";\n string res = \"\";\n ... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 3 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n stack<char>st;\n string result=\"\";\n\n int count=0;\n\n\n for(auto ch : s){\n\n if(ch != '-'){\n st.push(toupper(ch));\n }\n \n\n }\n\n ... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 3 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n int r = 0;\n string res = \"\";\n string q = \"\";\n for (auto i : s){\n if (i != '-'){\n r++;\n q.push_back(toupper(i));\n }\n }\n i... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 3 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n stack<char> letters;\n \n int n = s.length();\n int letterCount = 0;\n for(int i = n - 1; i > -1; --i) {\n if(s[i] != '-') {\n if(letterCount == k) {\n letters.push('-');\n ... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 3 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n stack<char> letters;\n \n int n = s.length();\n int letterCount = 0;\n for(int i = n - 1; i > -1; --i) {\n if(s[i] != '-') {\n if(letterCount == k) {\n letters.push('-');\n ... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 3 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n // Remove all dashes from the original string\n s.erase(remove(s.begin(), s.end(), '-'), s.end());\n \n // Convert all characters to uppercase\n for (auto& ch : s) {\n ch = toupper(... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 3 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n\n int cnt = 0;\n\n queue<char> q;\n for (char ch : s) {\n if (ch != '-') {\n q.push(toupper(ch)); // Convert to uppercase and push to queue\n cnt++;\n }\n... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 3 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n \n std::string cleaned;\n \n // Step 1: Remove all dashes and convert to uppercase\n for (char c : s) {\n if (c != '-') {\n cleaned += std::toupper(c);\n }\n }\n \n // St... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 3 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n if(k == 0 || s.size() == 0) return \"\";\n int c = 0, dashes = 0;\n string chars = \"\";\n for(auto x : s) {\n if(x != '-') {\n c++;\n if(!isdigit(x)) {\n ... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 3 | {
"code": "#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n string cleanStr;\n \n // Step 1: Remove all dashes and convert to uppercase\n for (char c : s) {\n if (c != '-') {\n cleanStr += t... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 3 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n string str = \"\";\n for (auto c : s) {\n if (c == '-') continue;\n if (isdigit(c)) str += c;\n else str += toupper(c);\n }\n\n string res = \"\";\n reverse(st... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 3 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n\n string normalString = \"\";\n for (auto x : s) {\n if(x!='-'){\n normalString += toupper(x);\n }\n }\n\n string ans = \"\";\n\n int length = normalString.len... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 3 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n transform(s.begin(), s.end(), s.begin(), ::toupper);\n string full=\"\";\n int count=0;\n for(int i=0;i<s.length();i++){\n if(s[i]!='-'){\n full+=s[i];\n coun... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 3 | {
"code": "/*\n20240820 18:01\n*/\nclass Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n string str = \"\";\n for (auto c : s) {\n if (isdigit(c) || isalpha(c)) str += toupper(c);\n }\n int n = str.size() / k;\n reverse(str.begin(), str.end());\n... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 3 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n transform(s.begin(), s.end(), s.begin(), ::toupper);\n string full=\"\";\n int count=0;\n for(int i=0;i<s.length();i++){\n if(s[i]!='-'){\n full+=s[i];\n coun... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 3 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n transform(s.begin(), s.end(), s.begin(), ::toupper);\n string full=\"\";\n int count=0;\n for(int i=0;i<s.length();i++){\n if(s[i]!='-'){\n full+=s[i];\n coun... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 3 | {
"code": "class Solution {\npublic:\n char to_capital(char a)\n {\n if(a >= 'a' && a <= 'z')\n return a - 'a' + 'A';\n return a; \n }\n string licenseKeyFormatting(string s, int k) {\n string temp = \"\";\n int n = s.length();\n stack<string> st;\n for... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 3 | {
"code": "#include <iostream>\n#include <string>\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n string ans = \"\";\n\n for (auto &x : s) {\n if (x != '-') {\n if (x >= 'a' && x <= 'z')\n ... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 3 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n string x=\"\";\n vector<string> v;\n for(auto c:s){\n if(c!='-'&& !isdigit(c)){\n x+=toupper(c); \n }else if(c!='-'&& isdigit(c)){\n x+=c;\n ... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 3 | {
"code": "#include <iostream>\n#include <string>\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n string ans = \"\";\n\n for (auto &x : s) {\n if (x != '-') {\n if (x >= 'a' && x <= 'z')\n ... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 3 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n vector<string> ans;\n string temp = \"\";\n \n // Remove dashes and convert to uppercase\n for (char c : s) {\n if (c != '-') {\n temp.push_back(toupper(c));\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 0 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n \n int iMax = 0;\n int iCurr = 0;\n for (int i = 0; i < nums.size(); ++i)\n {\n if (nums[i] == 1)\n {\n iCurr++;\n }\n else\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 0 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n int maxi = 0, count = 0;\n\n for(int i = 0; i<nums.size(); i++){\n if(nums[i] == 1){\n count++;\n maxi = max(maxi, count);\n }\n\n else{\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 0 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n \n int count = 0;\n int ans = 0;\n \n for(int i = 0; i < nums.size(); ++i) {\n \n if(nums[i] == 1) {\n ++count; \n } else {\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 0 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n\n int cnt = 0;\n int maxi = 0;\n for (int i = 0; i < nums.size(); i++) {\n if (nums[i] == 1) {\n cnt++;\n maxi = max(maxi, cnt);\n } else {\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 0 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n int max_count = 0;\n int current_count = 0;\n\n for (int num : nums) {\n if (num == 1) {\n current_count += 1;\n max_count = max(max_count, current_count);\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 0 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n int n=nums.size();\n int best=0,count=0;\n for(int i =0;i<n;i++){\n if(nums[i]==1) count++;\n else{\n \n count=0;\n }\n best=max(be... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 1 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n int max=0,count=0;\n int x=nums.size();\n for(int i=0;i<x;i++){\n if(nums[i]==1){\n count++;\n }else{\n if(count>max){\n max=count;\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 1 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n int cnt2 = 0;\n int cnt = 0;\n for (int i = 0; i < nums.size(); i++) {\n if (cnt==0) {\n if (nums[i] == 1)\n cnt++;\n }\n else if (nums[i] == 1 &&... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n int l = 0;\n int r = 0;\n int ans = 0;\n int ones = 0;\n int zeros = 0;\n while(r < nums.size())\n {\n if(nums[r] == 1) ones++;\n else zeros++;\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& arr) {\n vector<int> counter;\n \n int c = 1; \n if(arr.size() <= 1 &&arr[0]==1) return 0+1;\n if(arr.size()<=1 &&arr[0]==0) return 0;\n if(arr[0] == 0 && arr[1]==1 && arr.size() == 2)\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& arr) {\n vector<int> counter;\n \n int c = 1; \n if(arr.size() <= 1 &&arr[0]==1) return 0+1;\n if(arr.size()<=1 &&arr[0]==0) return 0;\n if(arr[0] == 0 && arr[1]==1 && arr.size() == 2)\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\nint maxValue(int a, int b) {\n return (a > b) ? a : b;\n}\n int findMaxConsecutiveOnes(vector<int>& nums) {\n \n string s = \"\";\n int size1 = 0;\n for(int i = 0 ; i<nums.size(); i++){\n if(nums[i] == 1){\n s+=nums[i];\... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n vector<int> myNums;\n bool ones = false;\n for (int i = 0; i < nums.size(); i++) {\n if (nums[i] == 1) {\n if (ones) {\n myNums[myNums.size() - 1]++;\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& arr) {\n vector<int>v;\n int count=0;\n for(int i=0;i<arr.size();i++){\n if(arr[i]==1){\n count++;\n }\n if(arr[i]==0 && count !=0 ){\n v.push_back(count);\n cou... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n stack<int> st;\n int maxCount = 0;\n if(nums.size() <= 0) return maxCount; \n maxCount = nums[0] == 1 ? 1 : 0;\n for(int i = 1; i < nums.size(); i++){\n if(nums[i] == 0) {\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n vector <int> v;\n int count=0;\n for(int i=0; i<nums.size(); i++){\n if((i+1)==nums.size() && nums[i]==1 ){\n count++;\n v.push_back(count);\n }\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n vector<int> v;\n int maxCount = 0;\n for(int i = 0; i < nums.size(); i++){\n if(nums[i] == 0) {\n v.push_back(maxCount);\n maxCount = 0;\n continue;\... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n vector<int> v;\n int maxCount = 0;\n for(int i = 0; i < nums.size(); i++){\n if(!nums[i]) {\n v.push_back(maxCount);\n maxCount = 0;\n continue;\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n vector<int>a;\n int count=0;\n nums.push_back(0);\n for(int i=0;i<nums.size();i++){\n if(nums[i]==1){\n count++;\n }\n else{\n a.push_b... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n vector<int>v; int ct=0;\n for(int i=0;i<nums.size();i++){\n if(nums[i]==1){\n ct++;\n }\n if(nums[i]!=1||i==nums.size()-1){\n v.push_back(ct);\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) \n {\n int n = nums.size();\n vector<int> pre(n+1,0);\n pre[1] = nums[0];\n for(int i=2;i<=n;i++)\n {\n if(nums[i-1]==1)\n pre[i] = pre[i-1]+nums[i-1];\n e... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n int n=nums.size();\n \n vector<int> b(n);\n int i,j;\n int count=0,max1=0;\n for(i=0;i<n;i++){\n if(nums[i]==1){\n count++; \n max1=max(max1,count);\n }\n els... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n int n = nums.size();\n vector<int> temp(n,0);\n\n int count;\n for(int i=0;i<n;i++){\n if(nums[i]!=0){\n count++;\n }else{\n temp[i] = count;\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n int n=nums.size();\n \n vector<int> b(n);\n int i,j;\n int count=0,max1=0;\n for(i=0;i<n;i++){\n if(nums[i]==1)\n count++; \n else\n count=0;\n max1=max(max... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n int n=nums.size();\n \n vector<int> b(n);\n int i,j;\n int count=0,max1=0;\n for(i=0;i<n;i++){\n if(nums[i]==1){\n count++; \n max1=max(max1,count);\n }\n els... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n vector<int> places; // To store positions of zeros\n vector<int> ones; // To store counts of consecutive ones\n\n // Step 1: Find the positions of all zeros\n for (int i = 0; i < nums.size(); i+... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n stack<int>st;\n int count =0;\n int n = nums.size();\n int max_count =0;\n if(nums[0]== 1)\n {\n count =1;\n }\n if(nums[0]== 1 && n==1)\n {\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n int n=nums.size();\n priority_queue<int> occ;\n\n int count=0;\n for(int i=0; i<n; i++){\n if(nums[i]==1){\n count++;\n }\n else if(nums[i]==0){\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n vector<int> v1;\n vector<int> v2;\n nums.push_back(0);\n for(int i=0;i<nums.size();i++){\n if(nums[i]==1){\n v1.push_back(1);\n }\n else{\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n vector<int> v1;\n vector<int> v2;\n nums.push_back(0);\n for(int i=0;i<nums.size();i++){\n if(nums[i]==1){\n v1.push_back(1);\n }\n else{\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n int j=0;\n vector<int>v(nums.size(),0);\n for(int i=0;i<nums.size();i++){\n if(nums[i]==1){\n v[j]++;\n \n }else if(nums[i]!=1){\n j++;\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n vector<int>prefix(nums.size());\n prefix[0]=nums[0];\n for(int i=1;i<nums.size();i++){\n int prev=prefix[i-1];\n if(nums[i]==0)prefix[i]=0;\n else prefix[i]=nums[i]+prev;\n... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "#include <bits/stdc++.h>\n#include<vector>\nclass Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {int n=nums.size();\n vector<int> vect(10);int count=0;\n for(int i=0;i<nums.size();i++){\n if(nums[i]==1){\n count++;vect.push_back(count);\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n int co=1;\n \n vector<int>v;\n\n for(int i=0;i<nums.size();i++){\n int count=0;\n for(int j=i;j<nums.size();j++){\n if(nums[j]==co){\n count++;\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n int co=1;\n \n vector<int>v;\n\n for(int i=0;i<nums.size();i++){\n int count=0;\n for(int j=i;j<nums.size();j++){\n if(nums[j]==co){\n count++;\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n int count=1;\n vector<int> count_arr;\n int max_count=0;\n for(int i=0;i<nums.size()-1;i++)\n {\n if(nums[i]==1&&nums[i+1]==1)\n {\n count++;\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int> nums) {\n int count = 0;\n int res = 0;\n nums.push_back(0);\n for (int i = 0; i < nums.size(); i++){\n if (nums[i] == 1) count ++;\n else{\n if (count > res) res = count;\... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n int count=0;\n vector<int> consec(nums.size());\n for(int i=0;i<nums.size();i++){\n if(nums[i]==1){\n count++;\n }\n else{\n consec.push_back(... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "#include <bits/stdc++.h>\n#include<vector>\nclass Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {int n=nums.size();\n vector<int> vect(2);int count=0;\n for(int i=0;i<nums.size();i++){\n if(nums[i]==1){\n count++;vect.push_back(count);\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n vector<int> a;\n int count=0;\n for(int i=0; i<nums.size(); i++){\n if(nums[i]==1){\n count++;\n if(nums[nums.size()-1]==1){\n a.push_back(count)... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n\n\n int count = 0;\n vector<int>temp;\n\n for(int i =0 ; i<nums.size() ; i++){\n \n if(nums[i] == 1){\n count ++;\n temp.push_back(count);\n }\n else{\n count = 0;\n }\n }\n int ans = 0;\... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n vector<int> a;\n int count=0;\n for(int i=0; i<nums.size(); i++){\n if(nums[i]==1){\n count++;\n if(nums[nums.size()-1]==1){\n a.push_back(count)... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n vector<int> v;\n int cnt = 0; int ans = 0;\n for(int i =0;i<nums.size();++i){\n if(nums[i] == 1){\n cnt++;\n ans = max(ans,cnt);\n v.push_back(ans);\... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n // int max=INT_MIN;\n int count =0;\n int sum=0;\n vector<int> ans;\n int n= nums.size();\n for(int i=0;i<n;i++){\n if(nums[i]==1) count++;\n ans.push_back(count);\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "#include <bits/stdc++.h>\n#include<vector>\nclass Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {int n=nums.size();\n vector<int> vect(n);int count=0;\n for(int i=0;i<nums.size();i++){\n if(nums[i]==1){\n count++;vect.push_back(count);\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "#include <bits/stdc++.h>\n#include<vector>\nclass Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {int n=nums.size();\n vector<int> vect(n);int count=0;\n for(int i=0;i<nums.size();i++){\n if(nums[i]==1){\n count++;vect.push_back(count);\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n int n=nums.size();\n vector <int> v;\n for(int i=0;i<n;i++){\n if(i==0){\n v.push_back(nums[0]);\n continue;\n }\n if(nums[i]==0){\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n // int max=INT_MIN;\n int count =0;\n int sum=0;\n vector<int> ans;\n int n= nums.size();\n for(int i=0;i<n;i++){\n if(nums[i]==1) count++;\n ans.push_back(count);\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n vector <int> s;\n int count =0;\n int m=0;\n for(int x=0;x<nums.size();x++){\n \n if(nums[x]==1){\n count+=1;\n }\n else {\n s.push_back(count);\n coun... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n int count = 0;\n int i = 0;\n vector<int> ans;\n while (i < nums.size()) {\n if(nums[i]==1)\n {\n count++;\n ans.push_back(count);\n }\... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n int count=0;\n vector<int>ans;\n for(int i=0;i<nums.size();i++){\n if(nums[i]==1){\n count++;\n }\n else{\n count=0;\n }\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n int l=nums.size();int c=0; vector<int>a; \n for(int i=0;i<l;i++){\n if (nums[i]==0){\n \n c=0;\n }\n else{\n c++; \n }\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n vector<int>ans;\n int count=0;\n for(int i=0;i<nums.size();i++){\n if(nums[i]==1){\n count++;\n }\n else if(nums[i]==0){\n ans.push_back(count... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\nint maxNo(vector<int> freq)\n{\n int maxno=INT_MIN;\n for(int i=0;i<freq.size();i++)\n maxno=max(maxno,freq[i]);\n return maxno;\n}\n int findMaxConsecutiveOnes(vector<int>& nums) {\n vector<int> freq;\n int c=0;\n for(int i=0;i<nums.size();i++... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n int count =0;\n set<int, greater<int>> maxr;\n for(int i : nums){\n if(i==1){\n count+=1;\n }\n else{\n maxr.insert(count);\n c... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n int n = nums.size(),cnt = 0;\n set<int>temp;\n for(int i = 0; i<n; i++){\n if(nums[i] == 1){\n cnt++;\n temp.insert(cnt);\n }else if(nums[i]==0){\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n int n = nums.size() , b=0;\n vector<int>freq(n,0);\n for(int i=0; i<n; i++){\n if(nums[i]!=0){\n b = b+1;\n }\n if(nums[i]==0){\n freq.push_ba... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n int max=0;\n int currmax=0;\n for(int i=0;i<nums.size();i++)\n {\n if(nums[i]==1)\n {\n currmax++;\n }\n if(nums[i]==0)\n {\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n int maxi = 0;//contains the value of consecutive no's of 1\n int count=0;//count the no.'s of 1 consecutively and reset to 0 when 0 come\n for(int i=0;i<nums.size();i++){\n //\n if(nums[i]==... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n int maxi = 0;\n int count = 0;\n for(int i=0;i<nums.size();i++)\n {\n if(nums[i]==1)\n {\n count++;\n maxi = max(maxi,count);\n }\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n \n int n=nums.size();\n int count=0;\n int max_count=0;\n\n for(int i=0;i<n;i++)\n {\n if(nums[i] == 1)\n count++;\n else\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n \n int maxi = 0 ;\n int cons = 0 ;\n\n for(int i = 0 ; i<nums.size() ; i++){\n\n if(nums[i] == 0){\n maxi = max(maxi,cons) ;\n cons = 0 ;\n }\n\n ... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n int maxCount = 0, currentCount = 0;\n \n for (int num : nums) {\n if (num == 1) {\n currentCount++;\n maxCount = max(maxCount, currentCount);\n } else {\n currentCoun... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n int n=nums.size();\n int count=0;\n int maxcount=0;\n for(int i =0 ; i<n;i++){\n if(nums[i] ==1){\n count++ ;\n maxcount = max(maxcount,count);\n }e... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n int mx=0;\n int cnt=0;\n for(int i=0;i<nums.size();i++)\n {\n if(i==0&&nums[i]==1)\n cnt++;\n if(i!=0&&nums[i]==1&&nums[i-1]==1)\n cnt++;\n els... |
485 | <p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,0,1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The ... | 2 | {
"code": "class Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n int maxCount = 0; \n int currentCount = 0; \n \n for (int num : nums) {\n if (num == 1) {\n currentCount++; \n } else {\n maxCount = max(maxCo... |
486 | <p>You are given an integer array <code>nums</code>. Two players are playing a game with this array: player 1 and player 2.</p>
<p>Player 1 and player 2 take turns, with player 1 starting first. Both players start the game with a score of <code>0</code>. At each turn, the player takes one of the numbers from either en... | 0 | {
"code": "class Solution {\npublic:\n bool predictTheWinner(vector<int>& nums) {\n\n int total = 0;\n for(auto it:nums) total += it;\n\n int s1 = firstScore(0, nums.size()-1, 0, nums);\n return s1 >= total - s1;\n }\n\n int firstScore(int i, int j, int t, vector<int>& nums) {\n ... |
486 | <p>You are given an integer array <code>nums</code>. Two players are playing a game with this array: player 1 and player 2.</p>
<p>Player 1 and player 2 take turns, with player 1 starting first. Both players start the game with a score of <code>0</code>. At each turn, the player takes one of the numbers from either en... | 0 | {
"code": "class Solution {\npublic:\n\nint solve(int i,int j,vector<int> & nums){\n if(i==j) return nums[i];\n if(i>j) return 0;\n\n int take_i=nums[i]+min(solve(i+2,j,nums),solve(i+1,j-1,nums));\n int take_j=nums[j]+min(solve(i,j-2,nums),solve(i+1,j-1,nums));\n return max(take_i,take_j);\n}\n bool... |
486 | <p>You are given an integer array <code>nums</code>. Two players are playing a game with this array: player 1 and player 2.</p>
<p>Player 1 and player 2 take turns, with player 1 starting first. Both players start the game with a score of <code>0</code>. At each turn, the player takes one of the numbers from either en... | 0 | {
"code": "class Solution {\npublic:\n int first(int left, int right, vector<int>& nums) {\n if (left == right)\n return nums[left];\n return max(nums[left] + slow(left + 1, right, nums),\n nums[right] + slow(left, right - 1, nums));\n }\n\n int slow(int left, int right, vecto... |
486 | <p>You are given an integer array <code>nums</code>. Two players are playing a game with this array: player 1 and player 2.</p>
<p>Player 1 and player 2 take turns, with player 1 starting first. Both players start the game with a score of <code>0</code>. At each turn, the player takes one of the numbers from either en... | 0 | {
"code": "class Solution{\npublic:\n // Create a Recursive 'Solve()' function which will return true if the score of 'player1' is greater than or equal to the\n // score of 'player2' \n bool Solve(vector<int> &nums, int i, int j, int score1, int score2, bool flag){\n // BASE CASE: If we finish select... |
486 | <p>You are given an integer array <code>nums</code>. Two players are playing a game with this array: player 1 and player 2.</p>
<p>Player 1 and player 2 take turns, with player 1 starting first. Both players start the game with a score of <code>0</code>. At each turn, the player takes one of the numbers from either en... | 0 | {
"code": "class Solution {\npublic:\n int first(int left, int right, vector<int>& nums) {\n if (left == right)\n return nums[left];\n return max(nums[left] + slow(left + 1, right, nums),\n nums[right] + slow(left, right - 1, nums));\n }\n\n int slow(int left, int right, vecto... |
486 | <p>You are given an integer array <code>nums</code>. Two players are playing a game with this array: player 1 and player 2.</p>
<p>Player 1 and player 2 take turns, with player 1 starting first. Both players start the game with a score of <code>0</code>. At each turn, the player takes one of the numbers from either en... | 0 | {
"code": "class Solution {\nprivate:\n int helper(vector<int>& nums, int l, int r) {\n if (l == r) {\n return nums[l];\n }\n\n int pickLeft = nums[l] - helper(nums, l + 1, r);\n int pickRight = nums[r] - helper(nums, l, r - 1);\n\n return max(pickLeft, pickRight);\n ... |
486 | <p>You are given an integer array <code>nums</code>. Two players are playing a game with this array: player 1 and player 2.</p>
<p>Player 1 and player 2 take turns, with player 1 starting first. Both players start the game with a score of <code>0</code>. At each turn, the player takes one of the numbers from either en... | 1 | {
"code": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n bool predictTheWinner(vector<int>& nums) {\n int n = nums.size();\n vector<vector<int>> dp(n, vector<int>(n, 0));\n\n for (int i = 0; i < n; ++i) {\n dp[i][i] = nums[i];\n }\n\n for (int ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.