id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
3,439
<p>There exist two <strong>undirected </strong>trees with <code>n</code> and <code>m</code> nodes, numbered from <code>0</code> to <code>n - 1</code> and from <code>0</code> to <code>m - 1</code>, respectively. You are given two 2D integer arrays <code>edges1</code> and <code>edges2</code> of lengths <code>n - 1</code>...
3
{ "code": "class Solution {\npublic:\n int minimumDiameterAfterMerge(vector<vector<int>>& edges1, vector<vector<int>>& edges2) {\n int d1 = 0, d2 = 0;\n int left = findLen(edges1, d1), right = findLen(edges2, d2);\n cout<<left<<\" \"<<right<<endl;\n return max({d1, d2, left+right+1});\n...
3,439
<p>There exist two <strong>undirected </strong>trees with <code>n</code> and <code>m</code> nodes, numbered from <code>0</code> to <code>n - 1</code> and from <code>0</code> to <code>m - 1</code>, respectively. You are given two 2D integer arrays <code>edges1</code> and <code>edges2</code> of lengths <code>n - 1</code>...
3
{ "code": "class Solution {\npublic:\n int minimumDiameterAfterMerge(vector<vector<int>>& edges1, vector<vector<int>>& edges2) {\n int d1 = 0, d2 = 0;\n int left = findLen(edges1, d1), right = findLen(edges2, d2);\n cout<<left<<\" \"<<right<<endl;\n return max({d1, d2, left+right+1});\n...
3,439
<p>There exist two <strong>undirected </strong>trees with <code>n</code> and <code>m</code> nodes, numbered from <code>0</code> to <code>n - 1</code> and from <code>0</code> to <code>m - 1</code>, respectively. You are given two 2D integer arrays <code>edges1</code> and <code>edges2</code> of lengths <code>n - 1</code>...
3
{ "code": "class Solution {\npublic:\n pair<int,int> radius(vector<set<int>> & adj,int n){\n queue<int>q;\n int curr_level=0;\n int next_level=0;\n int level=0;\n for(int i=0;i<n;i++){\n if(adj[i].size()==1) {q.push(i);curr_level++;}\n }\n int c=0;\n ...
3,439
<p>There exist two <strong>undirected </strong>trees with <code>n</code> and <code>m</code> nodes, numbered from <code>0</code> to <code>n - 1</code> and from <code>0</code> to <code>m - 1</code>, respectively. You are given two 2D integer arrays <code>edges1</code> and <code>edges2</code> of lengths <code>n - 1</code>...
3
{ "code": "class Solution {\npublic:\n int f(int node, int par, vector<int>adj[],int &diameter){\n int x = 1;\n vector<int>v;\n for(auto it:adj[node]){\n if(it!=par)\n v.push_back(f(it,node,adj,diameter));\n }\n sort(v.rbegin(),v.rend());\n if(v.s...
3,439
<p>There exist two <strong>undirected </strong>trees with <code>n</code> and <code>m</code> nodes, numbered from <code>0</code> to <code>n - 1</code> and from <code>0</code> to <code>m - 1</code>, respectively. You are given two 2D integer arrays <code>edges1</code> and <code>edges2</code> of lengths <code>n - 1</code>...
3
{ "code": "class Solution {\npublic:\n int diam(int node,vector<vector<int>>& adj,vector<int>& vis, int& d){\n vis[node]=1;\n priority_queue<int> maxh;\n for(int v:adj[node]){\n if(!vis[v]){\n maxh.push(diam(v,adj,vis,d));\n }\n }\n if(maxh.em...
3,439
<p>There exist two <strong>undirected </strong>trees with <code>n</code> and <code>m</code> nodes, numbered from <code>0</code> to <code>n - 1</code> and from <code>0</code> to <code>m - 1</code>, respectively. You are given two 2D integer arrays <code>edges1</code> and <code>edges2</code> of lengths <code>n - 1</code>...
3
{ "code": "class Solution {\npublic:\n pair <int ,int > func (int i,vector <int > g[]){\n vector <int > vis(100001,0);\n int d=-1;\n int last=-1;\n queue<int > q;\n q.push(i);\n vis[i]=1;\n while (!q.empty()){\n d++;\n int t=q.size();\n ...
3,439
<p>There exist two <strong>undirected </strong>trees with <code>n</code> and <code>m</code> nodes, numbered from <code>0</code> to <code>n - 1</code> and from <code>0</code> to <code>m - 1</code>, respectively. You are given two 2D integer arrays <code>edges1</code> and <code>edges2</code> of lengths <code>n - 1</code>...
3
{ "code": "class Solution {\npublic:\n void inDFS(int node ,int parent ,vector<vector<int>>& adj,int n,vector<int>&res){\n int temp = 0;\n for(auto &i : adj[node]){\n if(i == parent )continue;\n inDFS(i,node,adj,n,res);\n temp = max(temp,res[i]);\n }\n r...
3,439
<p>There exist two <strong>undirected </strong>trees with <code>n</code> and <code>m</code> nodes, numbered from <code>0</code> to <code>n - 1</code> and from <code>0</code> to <code>m - 1</code>, respectively. You are given two 2D integer arrays <code>edges1</code> and <code>edges2</code> of lengths <code>n - 1</code>...
3
{ "code": "class Solution {\npublic:\n void bfs(int node, map<int, vector<int>> &adj , int &returnNode, int &len){\n queue<pair<int,int>> q;\n int n = adj.size();\n if(n == 0) return ;\n vector<int> vis(n,0);\n vis[node] = 1;\n q.push({node, 0});\n while(!q.empty()...
3,439
<p>There exist two <strong>undirected </strong>trees with <code>n</code> and <code>m</code> nodes, numbered from <code>0</code> to <code>n - 1</code> and from <code>0</code> to <code>m - 1</code>, respectively. You are given two 2D integer arrays <code>edges1</code> and <code>edges2</code> of lengths <code>n - 1</code>...
3
{ "code": "class Solution {\npublic:\nint find(int i , int par,int &maxi , vector<vector<int>> &adj){\n vector<int>ans;\n for(auto it: adj[i]){\n if(it!=par){\n int x= find(it, i, maxi , adj);\n ans.push_back(x);\n }\n }\n if(ans.size()==0)return 1;\n sort(ans.rbeg...
3,439
<p>There exist two <strong>undirected </strong>trees with <code>n</code> and <code>m</code> nodes, numbered from <code>0</code> to <code>n - 1</code> and from <code>0</code> to <code>m - 1</code>, respectively. You are given two 2D integer arrays <code>edges1</code> and <code>edges2</code> of lengths <code>n - 1</code>...
3
{ "code": "class Solution {\npublic:\n pair<int,int> findFarthest(int src, int parent, map<int,vector<int>> &tree)\n {\n int maxDist=-1;\n pair<int,int> ans;\n for(auto i:tree[src])\n {\n if(i!=parent)\n {\n auto tmp = findFarthest(i,src,tree);\n ...
3,439
<p>There exist two <strong>undirected </strong>trees with <code>n</code> and <code>m</code> nodes, numbered from <code>0</code> to <code>n - 1</code> and from <code>0</code> to <code>m - 1</code>, respectively. You are given two 2D integer arrays <code>edges1</code> and <code>edges2</code> of lengths <code>n - 1</code>...
3
{ "code": "class Solution {\npublic:\n int ans=0;\nint finddia(unordered_map<int,vector<int>> &gp, int src, int parent) {\n priority_queue<int> pq;\n \n for (auto i : gp[src]) {\n if (i != parent) {\n int childheight = finddia(gp, i, src);\n pq.push(childheight);\n }\n ...
3,439
<p>There exist two <strong>undirected </strong>trees with <code>n</code> and <code>m</code> nodes, numbered from <code>0</code> to <code>n - 1</code> and from <code>0</code> to <code>m - 1</code>, respectively. You are given two 2D integer arrays <code>edges1</code> and <code>edges2</code> of lengths <code>n - 1</code>...
3
{ "code": "#include <cmath>\n\nusing namespace std;\n\nclass Solution {\npublic:\n int dfs(int node, vector<bool>& t, int& longest, unordered_map<int, vector<int>>& g) {\n t[node] = true;\n int l1 = 0, l2 = 0, l = 0;\n for (auto v: g[node])\n if (not t[v]) {\n l = dfs...
3,439
<p>There exist two <strong>undirected </strong>trees with <code>n</code> and <code>m</code> nodes, numbered from <code>0</code> to <code>n - 1</code> and from <code>0</code> to <code>m - 1</code>, respectively. You are given two 2D integer arrays <code>edges1</code> and <code>edges2</code> of lengths <code>n - 1</code>...
3
{ "code": "class Solution {\n vector<vector<int>> g;\n vector<int> in,out;\n void inCalculation(int src,int par){\n in[src] = 1;\n for( auto i : g[src]){\n if(i == par) continue; // we don't want to go back the same path\n\n inCalculation(i,src);\n in[src] = max...
3,439
<p>There exist two <strong>undirected </strong>trees with <code>n</code> and <code>m</code> nodes, numbered from <code>0</code> to <code>n - 1</code> and from <code>0</code> to <code>m - 1</code>, respectively. You are given two 2D integer arrays <code>edges1</code> and <code>edges2</code> of lengths <code>n - 1</code>...
3
{ "code": "class Solution {\n \n vector<vector<int>> g;\n vector<int> in, out;\n \n void inCalculation (int src, int par) {\n in[src] = 1;\n \n for (auto i: g[src]) {\n if (i == par) continue;\n \n inCalculation(i, src);\n in[src] = max (...
3,439
<p>There exist two <strong>undirected </strong>trees with <code>n</code> and <code>m</code> nodes, numbered from <code>0</code> to <code>n - 1</code> and from <code>0</code> to <code>m - 1</code>, respectively. You are given two 2D integer arrays <code>edges1</code> and <code>edges2</code> of lengths <code>n - 1</code>...
3
{ "code": "class Solution {\npublic: \n int farthest_node(vector<vector<int>>adj){\n queue<int>q;\n vector<int>visited(adj.size(),0);\n q.push(0);\n visited[0]=1;\n int last;\n while(!q.empty()){\n int node=q.front();\n q.pop();\n last=node...
3,439
<p>There exist two <strong>undirected </strong>trees with <code>n</code> and <code>m</code> nodes, numbered from <code>0</code> to <code>n - 1</code> and from <code>0</code> to <code>m - 1</code>, respectively. You are given two 2D integer arrays <code>edges1</code> and <code>edges2</code> of lengths <code>n - 1</code>...
3
{ "code": "class Solution {\npublic:\n int first = 0, second = 0;\n pair<int, int> bfs(int start, unordered_map<int, vector<int>>& graph, int tmp) {\n int n = tmp;\n vector<int> distance(n, -1);\n queue<int> q;\n\n q.push(start);\n distance[start] = 0;\n\n int farthestNode = start;\n int ma...
3,439
<p>There exist two <strong>undirected </strong>trees with <code>n</code> and <code>m</code> nodes, numbered from <code>0</code> to <code>n - 1</code> and from <code>0</code> to <code>m - 1</code>, respectively. You are given two 2D integer arrays <code>edges1</code> and <code>edges2</code> of lengths <code>n - 1</code>...
3
{ "code": "class Solution {\npublic:\n\n void adjList(vector<vector<int>>&adj, vector<vector<int>>& edges){\n for(auto it:edges){\n int u = it[0];\n int v = it[1];\n adj[u].push_back(v);\n adj[v].push_back(u);\n }\n }\n\n void solve(int src, vector<ve...
3,439
<p>There exist two <strong>undirected </strong>trees with <code>n</code> and <code>m</code> nodes, numbered from <code>0</code> to <code>n - 1</code> and from <code>0</code> to <code>m - 1</code>, respectively. You are given two 2D integer arrays <code>edges1</code> and <code>edges2</code> of lengths <code>n - 1</code>...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> makegraph(vector<vector<int>>& edges)\n {\n int n=edges.size();\n vector<vector<int>>ans(n+1);\n for(auto edge:edges)\n {\n int u=edge[0];\n int v=edge[1];\n ans[u].push_back(v);...
3,439
<p>There exist two <strong>undirected </strong>trees with <code>n</code> and <code>m</code> nodes, numbered from <code>0</code> to <code>n - 1</code> and from <code>0</code> to <code>m - 1</code>, respectively. You are given two 2D integer arrays <code>edges1</code> and <code>edges2</code> of lengths <code>n - 1</code>...
3
{ "code": "class Solution {\npublic:\n\n vector<int> bfs(vector<vector<int>> &graph,int source){\n queue<int> q;\n int maxDistance=0;\n int node=source;\n q.push(source);\n map<int,int> visited;\n visited[source]=1;\n\n while(!q.empty()){\n int n=q.size()...
3,439
<p>There exist two <strong>undirected </strong>trees with <code>n</code> and <code>m</code> nodes, numbered from <code>0</code> to <code>n - 1</code> and from <code>0</code> to <code>m - 1</code>, respectively. You are given two 2D integer arrays <code>edges1</code> and <code>edges2</code> of lengths <code>n - 1</code>...
3
{ "code": "class Solution {\npublic:\n\n int mid(vector<int>& in, vector<int> adj[])\n {\n queue<int> q;\n for(int i = 0; i < in.size(); i++)\n if(in[i]==1) q.push(i);\n int ans = 0;\n\n while(q.size())\n {\n int node = q.front();\n q.pop();\n ...
3,439
<p>There exist two <strong>undirected </strong>trees with <code>n</code> and <code>m</code> nodes, numbered from <code>0</code> to <code>n - 1</code> and from <code>0</code> to <code>m - 1</code>, respectively. You are given two 2D integer arrays <code>edges1</code> and <code>edges2</code> of lengths <code>n - 1</code>...
3
{ "code": "class Solution {\npublic:\n int minimumDiameterAfterMerge(vector<vector<int>>& edges1, vector<vector<int>>& edges2) {\n int dia1 = calculateDiameter(edges1);\n int dia2 = calculateDiameter(edges2);\n \n int half_dia1 = (dia1 + 1) / 2;\n int half_dia2 = (dia2 + 1) / 2;\...
3,439
<p>There exist two <strong>undirected </strong>trees with <code>n</code> and <code>m</code> nodes, numbered from <code>0</code> to <code>n - 1</code> and from <code>0</code> to <code>m - 1</code>, respectively. You are given two 2D integer arrays <code>edges1</code> and <code>edges2</code> of lengths <code>n - 1</code>...
3
{ "code": "class Solution {\npublic:\n void dfs1(int s, int p, vector<vector<int>> &adj, vector<int> & max_child, vector<int> & child_max1, vector<int> & child_max2){\n set<pair<int, int>> se;\n for(auto v: adj[s]){\n if(v!= p){\n dfs1(v, s, adj, max_child, child_max1, child...
3,463
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>colors[i] == 1</code> means th...
0
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors) {\n int count=0;\n int n=colors.size();\n for(int i=1;i<colors.size()-1;i++){\n if(colors[i]!=colors[i-1] && colors[i]!=colors[i+1]){\n count++;\n }\n\n }\n if(colors[0]=...
3,463
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>colors[i] == 1</code> means th...
0
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors) {\n int n =colors.size();\n int ans =0;\n for(int i=0;i<n-2;i++)\n {\n if(colors[i]==colors[i+2]&& colors[i]!=colors[i+1])\n {\n ans++;\n }\n ...
3,463
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>colors[i] == 1</code> means th...
0
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors) {\n int res=0;\n if(colors[colors.size()-1]!=colors[0] && colors[0]!=colors[1]){\n res++;\n }\n for(int i=1;i<colors.size()-1;i++){\n if(colors[i-1]!=colors[i] && colors[i]!=c...
3,463
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>colors[i] == 1</code> means th...
0
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors) {\n int l = 0, r = 1, n = colors.size(), ans = 0;\n for(int i= 0 ; i<n; i++){\n if(colors[l]!=colors[r]){\n if(colors[l] == colors[(r+1)%n]){\n ans++;\n ...
3,463
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>colors[i] == 1</code> means th...
0
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors) {\n int n= colors.size();\n int cnt=0;\n for( int i=0; i<n; i++){\n if(colors[(i+n-1)%n]== !colors[i] && colors[(i+1)%n]== !colors[i] ){\n cnt++;\n }\n }\n ...
3,463
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>colors[i] == 1</code> means th...
0
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors) {\n int n = colors.size();\n int ans = 0;\n int i=1;\n\n while(i<=n){\n if(colors[(i-1)%n] != colors[i%n] && colors[i%n]!=colors[(i+1)%n]){\n ans++;\n }\n ...
3,463
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>colors[i] == 1</code> means th...
1
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors) {\n int ans = 0, n = colors.size();\n\n for(int i = 0; i<n; i++){\n if(colors[(i+1)%n] != colors[i%n] && colors[(i+1)%n] != colors[(i+2)%n]) ans++;\n }\n\n return ans;\n }\n};", "me...
3,463
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>colors[i] == 1</code> means th...
1
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& c) {\n int ans=0;\n int n=c.size();\n for(int i=1;i<n-1;i++){\n if(c[i]!=c[i-1] && c[i]!=c[i+1]){\n ans++;\n }\n }\n if(c[0]!=c[1] && c[0]!= c[n-1]){\n ...
3,463
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>colors[i] == 1</code> means th...
3
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& arr) {\n int n = arr.size();\n int ans = 0;\n for(int i=0; i<n; i++){\n int next = (i+1)%n;\n int prev = (i-1+n)%n;\n if(arr[i]!=arr[next] && arr[i]!=arr[prev]){\n ...
3,463
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>colors[i] == 1</code> means th...
3
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors) {\n int count=0;\n int n=colors.size();\n for(int i=0;i<colors.size();i++){\n int prev=colors[i];\n int curr=colors[(i+1)%n];\n int next=colors[(i+2)%n];\n if(c...
3,463
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>colors[i] == 1</code> means th...
3
{ "code": "class Solution {\npublic:\n Solution() {ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); }\n int numberOfAlternatingGroups(vector<int>& colors) {\n int n = colors.size();\n int altCount = 0;\n for (int i = 0; i < n; i++) \n altCount += ((colors[(i + n - 1) % ...
3,463
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>colors[i] == 1</code> means th...
3
{ "code": "class Solution {\npublic:\n Solution() {ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); }\n int numberOfAlternatingGroups(vector<int>& colors) {\n int n = colors.size();\n int left = colors[n - 2];\n int mid = colors[n - 1];\n int altCount = 0;\n for (int...
3,463
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>colors[i] == 1</code> means th...
3
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors) {\n int n = colors.size();\n for(int i=0;i<n;i++)\n colors.push_back(colors[i]);\n \n int ans = 0;\n for(int i=0;i<n;i++)\n if(colors[i] == colors[i+2] and colors[i] != ...
3,264
<p>You are given an integer array <code>enemyEnergies</code> denoting the energy values of various enemies.</p> <p>You are also given an integer <code>currentEnergy</code> denoting the amount of energy you have initially.</p> <p>You start with 0 points, and all the enemies are unmarked initially.</p> <p>You can perf...
0
{ "code": "class Solution {\npublic:\n long long maximumPoints(vector<int>& enemyEnergies, int currentEnergy) {\n ios::sync_with_stdio(0);\n\t\tcin.tie(0);\n\t\tcout.tie(0);\n std::nth_element(enemyEnergies.begin(),enemyEnergies.begin(),enemyEnergies.end());\n long long ans = 0;\n // 2 ...
3,264
<p>You are given an integer array <code>enemyEnergies</code> denoting the energy values of various enemies.</p> <p>You are also given an integer <code>currentEnergy</code> denoting the amount of energy you have initially.</p> <p>You start with 0 points, and all the enemies are unmarked initially.</p> <p>You can perf...
0
{ "code": "class Solution {\npublic:\n long long maximumPoints(vector<int>& enemyEnergies, int currentEnergy) {\n long long curr=currentEnergy;\n int mini=enemyEnergies[0];\n for(int i=1;i<enemyEnergies.size();i++){\n if(mini>enemyEnergies[i]){\n curr+=mini;\n ...
3,264
<p>You are given an integer array <code>enemyEnergies</code> denoting the energy values of various enemies.</p> <p>You are also given an integer <code>currentEnergy</code> denoting the amount of energy you have initially.</p> <p>You start with 0 points, and all the enemies are unmarked initially.</p> <p>You can perf...
0
{ "code": "auto init = []()\n{ \n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n return 'c';\n}();\nclass Solution {\npublic:\n long long maximumPoints(vector<int>& enemyEnergies, int currentEnergy) {\n int minE = enemyEnergies[0];\n long long tot = 0;\n\n for (int e: enem...
3,264
<p>You are given an integer array <code>enemyEnergies</code> denoting the energy values of various enemies.</p> <p>You are also given an integer <code>currentEnergy</code> denoting the amount of energy you have initially.</p> <p>You start with 0 points, and all the enemies are unmarked initially.</p> <p>You can perf...
0
{ "code": "class Solution {\npublic:\n long long maximumPoints(vector<int>& enemyEnergies, int currentEnergy) {\n long long points = 0; \n long long min_energy = 1e9;\n long long total_energy = currentEnergy;\n for(long long e : enemyEnergies){\n total_energy += e;\n ...
3,264
<p>You are given an integer array <code>enemyEnergies</code> denoting the energy values of various enemies.</p> <p>You are also given an integer <code>currentEnergy</code> denoting the amount of energy you have initially.</p> <p>You start with 0 points, and all the enemies are unmarked initially.</p> <p>You can perf...
0
{ "code": "class Solution {\npublic:\n long long maximumPoints(vector<int>& enemyEnergies, int currentEnergy) {\n int minimumElement=*min_element(enemyEnergies.begin(), enemyEnergies.end());\n long long int sum=0;\n\n //no points can be gained;\n if(currentEnergy < minimumElement){\n ...
3,264
<p>You are given an integer array <code>enemyEnergies</code> denoting the energy values of various enemies.</p> <p>You are also given an integer <code>currentEnergy</code> denoting the amount of energy you have initially.</p> <p>You start with 0 points, and all the enemies are unmarked initially.</p> <p>You can perf...
0
{ "code": "class Solution {\npublic:\n long long maximumPoints(vector<int>& enemyEnergies, int currentEnergy) {\n int mn = INT_MAX;\n long long sum = 0;\n\n for(int i=0;i<enemyEnergies.size();++i)\n {\n sum += enemyEnergies[i];\n\n if(mn > enemyEnergies[i])\n ...
3,264
<p>You are given an integer array <code>enemyEnergies</code> denoting the energy values of various enemies.</p> <p>You are also given an integer <code>currentEnergy</code> denoting the amount of energy you have initially.</p> <p>You start with 0 points, and all the enemies are unmarked initially.</p> <p>You can perf...
0
{ "code": "class Solution {\npublic:\n long long maximumPoints(vector<int>& enemyEnergies, int currentEnergy) {\n int minEnergy = *min_element(enemyEnergies.begin(), enemyEnergies.end());\n\n if(minEnergy > currentEnergy) return 0;\n long sum = 0;\n for (auto energy : enemyEnergies) sum...
3,264
<p>You are given an integer array <code>enemyEnergies</code> denoting the energy values of various enemies.</p> <p>You are also given an integer <code>currentEnergy</code> denoting the amount of energy you have initially.</p> <p>You start with 0 points, and all the enemies are unmarked initially.</p> <p>You can perf...
0
{ "code": "class Solution {\npublic:\n long long maximumPoints(vector<int>& enemyEnergies, int currentEnergy) {\n std::ios::sync_with_stdio(0);\n std::cin.tie(0);\n long long points=0;\n sort(enemyEnergies.begin(),enemyEnergies.end());\n int j=enemyEnergies.size()-1;\n int...
3,264
<p>You are given an integer array <code>enemyEnergies</code> denoting the energy values of various enemies.</p> <p>You are also given an integer <code>currentEnergy</code> denoting the amount of energy you have initially.</p> <p>You start with 0 points, and all the enemies are unmarked initially.</p> <p>You can perf...
0
{ "code": "class Solution {\npublic:\n long long maximumPoints(vector<int>& a, int curr) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n int n = a.size();\n long long pts = 0;\n sort(a.begin(), a.end());\n int l = 0, r = n - 1;\n while (l <= r) {\n ...
3,264
<p>You are given an integer array <code>enemyEnergies</code> denoting the energy values of various enemies.</p> <p>You are also given an integer <code>currentEnergy</code> denoting the amount of energy you have initially.</p> <p>You start with 0 points, and all the enemies are unmarked initially.</p> <p>You can perf...
0
{ "code": "class Solution {\npublic:\n long long maximumPoints(vector<int>& enemyEnergies, int currentEnergy) {\n sort(enemyEnergies.begin(), enemyEnergies.end());\n int fight = 0;\n int add = enemyEnergies.size() - 1;\n long long res = 0;\n while(add >= 0){\n if(curre...
3,264
<p>You are given an integer array <code>enemyEnergies</code> denoting the energy values of various enemies.</p> <p>You are also given an integer <code>currentEnergy</code> denoting the amount of energy you have initially.</p> <p>You start with 0 points, and all the enemies are unmarked initially.</p> <p>You can perf...
0
{ "code": "class Solution {\npublic:\n long long maximumPoints(vector<int>& enemyEnergies, int currentEnergy) {\n ios::sync_with_stdio(false);\n cin.tie(0);\n //we need to find th emaximum points at the end of the game\n //for the first time we need to choose the enemy to gain 1 point a...
3,264
<p>You are given an integer array <code>enemyEnergies</code> denoting the energy values of various enemies.</p> <p>You are also given an integer <code>currentEnergy</code> denoting the amount of energy you have initially.</p> <p>You start with 0 points, and all the enemies are unmarked initially.</p> <p>You can perf...
1
{ "code": "class Solution {\npublic:\n long long maximumPoints(vector<int>& enemyEnergies, int currentEnergy) {\n long long sum=currentEnergy;\n sort(enemyEnergies.begin(),enemyEnergies.end());\n if(sum<enemyEnergies[0]) return 0;\n for(int i=0;i<enemyEnergies.size();i++)\n {\n ...
3,264
<p>You are given an integer array <code>enemyEnergies</code> denoting the energy values of various enemies.</p> <p>You are also given an integer <code>currentEnergy</code> denoting the amount of energy you have initially.</p> <p>You start with 0 points, and all the enemies are unmarked initially.</p> <p>You can perf...
1
{ "code": "class Solution {\npublic:\n long long maximumPoints(vector<int>& arr, int currentEnergy) {\n int i = 0;\n int j = arr.size()-1;\n\n long long points = 0;\n long long energy = currentEnergy;\n\n sort(arr.begin(), arr.end());\n\n if(energy < arr[0])\n r...
3,264
<p>You are given an integer array <code>enemyEnergies</code> denoting the energy values of various enemies.</p> <p>You are also given an integer <code>currentEnergy</code> denoting the amount of energy you have initially.</p> <p>You start with 0 points, and all the enemies are unmarked initially.</p> <p>You can perf...
2
{ "code": "class Solution {\npublic:\n typedef long long ll;\n ll solve(vector<int>& enemyEnergies, int currentEnergy, int i, int j)\n {\n ll ans = 0;\n while(i <= j) \n {\n if(enemyEnergies[i] > currentEnergy) \n {\n if(ans == 0) \n {\...
3,264
<p>You are given an integer array <code>enemyEnergies</code> denoting the energy values of various enemies.</p> <p>You are also given an integer <code>currentEnergy</code> denoting the amount of energy you have initially.</p> <p>You start with 0 points, and all the enemies are unmarked initially.</p> <p>You can perf...
2
{ "code": "class Solution {\npublic:\n long long maximumPoints(vector<int>& enemyEnergies, int currentEnergy) {\n long long ans = 0;\n long long energy = currentEnergy;\n\n sort(enemyEnergies.begin(), enemyEnergies.end());\n\n int i = 0;\n int j = enemyEnergies.size()-1;\n\n ...
3,264
<p>You are given an integer array <code>enemyEnergies</code> denoting the energy values of various enemies.</p> <p>You are also given an integer <code>currentEnergy</code> denoting the amount of energy you have initially.</p> <p>You start with 0 points, and all the enemies are unmarked initially.</p> <p>You can perf...
3
{ "code": "class Solution {\npublic:\n long long maximumPoints(vector<int>& enemyEnergies, int currentEnergy) {\n long long p = 0, n = enemyEnergies.size(), j = n - 1;\n sort(enemyEnergies.begin(), enemyEnergies.end());\n if(enemyEnergies[0] > currentEnergy) return 0;\n while(j >= 0){\n...
3,264
<p>You are given an integer array <code>enemyEnergies</code> denoting the energy values of various enemies.</p> <p>You are also given an integer <code>currentEnergy</code> denoting the amount of energy you have initially.</p> <p>You start with 0 points, and all the enemies are unmarked initially.</p> <p>You can perf...
3
{ "code": "class Solution {\npublic:\n long long maximumPoints(vector<int>& enemyEnergies, int currentEnergy) {\n long long max_points = 0;\n if(!currentEnergy) {\n return 0;\n }\n std::size_t N = enemyEnergies.size();\n std::sort(enemyEnergies.begin(), enemyEnergies.e...
3,264
<p>You are given an integer array <code>enemyEnergies</code> denoting the energy values of various enemies.</p> <p>You are also given an integer <code>currentEnergy</code> denoting the amount of energy you have initially.</p> <p>You start with 0 points, and all the enemies are unmarked initially.</p> <p>You can perf...
3
{ "code": "class Solution {\npublic:\n long long maximumPoints(vector<int>& enemyEnergies, int currentEnergy) {\n long long max_points = 0;\n if(!currentEnergy) {\n return 0;\n }\n std::size_t N = enemyEnergies.size();\n std::sort(enemyEnergies.begin(), enemyEnergies.e...
3,264
<p>You are given an integer array <code>enemyEnergies</code> denoting the energy values of various enemies.</p> <p>You are also given an integer <code>currentEnergy</code> denoting the amount of energy you have initially.</p> <p>You start with 0 points, and all the enemies are unmarked initially.</p> <p>You can perf...
3
{ "code": "class Solution {\npublic:\n long long maximumPoints(vector<int>& enemyEnergies, int currentEnergy) {\n long long n = enemyEnergies.size();\n sort(enemyEnergies.begin(),enemyEnergies.end());\n vector<bool> marked(n,false);\n if(currentEnergy==0) return 0;\n long long an...
3,264
<p>You are given an integer array <code>enemyEnergies</code> denoting the energy values of various enemies.</p> <p>You are also given an integer <code>currentEnergy</code> denoting the amount of energy you have initially.</p> <p>You start with 0 points, and all the enemies are unmarked initially.</p> <p>You can perf...
3
{ "code": "class Solution {\npublic:\n long long maximumPoints(vector<int>& enemyEnergies, int currentEnergy) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n int n = enemyEnergies.size();\n sort(enemyEnergies.rbegin(), enemyEnergies.rend());\n long long ans = 0;\n ...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
0
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& a, int k) {\n int fault = -1;\n int n=a.size();\n int i;\n for(i = 0;i<k-1;i++){\n if(a[i]==a[i+1]){\n fault = i;\n }\n }\n int count = 0;\n if(fau...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
0
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& arr, int k) {\n int start=0;\n int end=1;\n int ans=0;\n while(start<arr.size()){\n if(start<end){\n \n if(arr[end]!=arr[end-1]){\n if(end-start+...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
0
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n \n int maxLen = 1, ans = 0, n = colors.size();\n for(int i=1; i<= n-1+k-1; i++){\n if(colors[i%n] != colors[(i-1+n)%n]){\n maxLen++;\n }else{\n ...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
0
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& arr, int k) {\n int start=0;\n int end=1;\n int ans=0;\n while(start<arr.size()){\n if(start<end){\n \n if(arr[end]!=arr[end-1]){\n if(end-start+...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
1
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) \n {\n int n = colors.size();\n set<int> str;\n for(int i = 0; i < (k-1); ++i)\n {\n if(colors[i] == colors[(i+1)%n])\n {\n str.insert(i);\n ...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
1
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n int i=0,j=0,n=colors.size();\n map<int,int> map;\n int c=j;\n bool isAlternative=true;\n int idx=-1;\n int count=0;\n while(i<n){\n map[colors[j]]++;\n ...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
1
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n int i=0,j=0,n=colors.size();\n map<int,int> map;\n int c=j;\n bool isAlternative=true;\n int idx=-1;\n int count=0;\n while(i<n){\n map[colors[j]]++;\n ...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
1
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& a, int k) {\n int n=a.size();\n vector<bool> b(n);\n vector<int> store;\n for(int i=0;i<n;i++){\n if(i!=n-1){\n if(a[i]!=a[i+1]) b[i]=true;\n else {\n ...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
1
{ "code": "const int MAXNODES = (int)4e5 + 1;\nint segTree[MAXNODES];\nvector<int> pColor;\nint mayer = 1;\nint crock = 2;\nclass Solution {\npublic:\n int initialSegTree(int node, int left, int right) {\n if (left == right) {\n segTree[node] = 1; // 색상을 그대로 넣습니다.\n return segTree[node...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
1
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n int n = colors.size();\n vector<int> diff(n,0);\n int d = 0;\n for(int i=n-k + 2;i <n; i++){\n if(colors[i]!=colors[i-1]) d++;\n else d=0;\n }\n if(co...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
1
{ "code": "class Solution {\npublic:\n bool isAlternating(int beg,int end, vector<int>& isValid, int k){\n if(beg<end){\n int curr = isValid[end];\n int prev = (beg==0?0:isValid[beg]);\n int onesCnt = curr-prev;\n int elementCnt = k;\n if(onesCnt<=eleme...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
1
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& c, int k) {\n int len =c.size();\n vector<int> lac(len,0);\n lac[0]=1;\n for(int i=1;i<len;++i){\n if(c[i]!=c[i-1]){\n lac[i]=lac[i-1]+1;\n } else{\n lac...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
1
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n int ans=0;\n int n=colors.size();\n vector<int>arr(n);\n set<int>fault;\n int i=0;\n int j=k-1;\n for(int i=0;i<k-1;i++){\n if(colors[i]==colors[i+1]){\n ...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
1
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& A, int k) {\n \n int n=A.size(),cnt=0,len=1;\n A.insert(A.end(),A.begin(),A.begin()+k-1);\n\n\n for(int i=1;i<n+k-1;i++)\n {\n if(A[i]!=A[i-1]) len++;\n else len=1;\n\n ...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
1
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n int ans = 0, cnt = 1;\n colors.insert(colors.end(), colors.begin(), colors.begin() + k - 1);\n for(int i = 1; i < colors.size(); i++) {\n if(colors[i] != colors[i-1])\n ...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
1
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& A, int k) {\n \n int n=A.size(),cnt=0,len=1;\n A.insert(A.end(),A.begin(),A.begin()+k-1);\n\n\n for(int i=1;i<n+k-1;i++)\n {\n if(A[i]!=A[i-1]) len++;\n else len=1;\n\n ...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
2
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n for (int i = 0; i < k - 1; ++i) colors.push_back(colors[i]);\n int res = 0;\n int cnt = 1;\n for (int i = 1; i < colors.size(); ++i) {\n if (colors[i] != colors[i - 1]) ++cnt;...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
2
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n for (int i = 0; i < k - 1; ++i) colors.push_back(colors[i]);\n int res = 0;\n int cnt = 1;\n for (int i = 1; i < colors.size(); ++i) {\n if (colors[i] != colors[i - 1]) ++cnt;...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
2
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n for (int i = 0; i < k - 1; ++i) colors.push_back(colors[i]);\n int res = 0;\n int cnt = 1;\n for (int i = 1; i < colors.size(); ++i) {\n if (colors[i] != colors[i - 1]) ++cnt;...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
2
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& col, int k) {\n \n for(int i=0;i<k-1;i++)\n {\n col.push_back(col[i]);\n }\n int n=col.size();\n int maxlen=1;\n int cnt=0;\n for(int i=1;i<n;i++)\n {\n ...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
2
{ "code": "#include <vector>\n\nclass Solution {\npublic:\n int numberOfAlternatingGroups(std::vector<int>& colors, int k) {\n // Store the last color we processed\n int lastColor = colors[0];\n // Count of alternating colors, initialized to 1 for the first color\n int altColorsCount = ...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
2
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n int total = 1;\n int j = 0;\n int r = k - 1;\n while (r--) {\n colors.push_back(colors[j]);\n j += 1;\n }\n bool check = 1;\n int ans = 0;\n ...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
2
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n for (int i = 0; i < k - 1; ++i) colors.push_back(colors[i]);\n int res = 0;\n int cnt = 1;\n for (int i = 1; i < colors.size(); ++i) {\n if (colors[i] != colors[i - 1]) ++cnt;...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
2
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n const int n = colors.size();\n vector<int> ccpy(n+k-1,0);\n ccpy[0] = 1;\n for (int i = 1; i < n+k-1; ++i) {\n int pc = colors[(i-1) % n];\n int c = colors[i % n];\...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
3
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n int n = colors.size(), m = n + k - 1, idx = 0;\n vector<int> arr(m);\n for (int i = 0; i < m; i++) {\n arr[i] = colors[i % n];\n }\n int ans = 0, l = 0, r = 1;\n ...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
3
{ "code": "class Solution {\npublic:\n int ans = 0;\n vector<int> findFinalValue(int start , int k , vector<int>& colors){\n int finl = start+k; \n int n = colors.size();\n int flag=0;\n while(start < n && start < finl){\n if(colors[start]==colors[start-1]){\n ...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
3
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n \n int n = colors.size();\n vector<int>tile(n+k-1);\n copy(colors.begin(),colors.end(),tile.begin());\n copy(colors.begin(),colors.begin()+k-1,tile.begin()+n);\n \n vec...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
3
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n string str,temp;\n for(auto i:colors)\n temp+=to_string(i);\n str=temp+temp; \n str.pop_back();\n int n1=temp.size();\n n1=n1+k-1;\n int i=0,j=1,n=str.size()...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
3
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n string c=\"\";\n for(int it: colors) c+=(it+'0');\n c+=c;\n\n string a=\"0\", b=\"1\";\n for(int i=1;i<k;i++){\n a+= a.back() == '0' ? '1' : '0';\n }\n\n ...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
3
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n string c=\"\";\n for(int it: colors) c+=(it+'0');\n c+=c;\n\n string a=\"0\", b=\"1\";\n for(int i=1;i<k;i++){\n a+= a.back() == '0' ? '1' : '0';\n }\n\n ...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
3
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n int n = colors.size();\n for(int i=0;i<k-1;i++){\n colors.push_back(colors[i]);\n }\n n=colors.size();\n vector<bool> both(n, false);\n vector<bool> left(n, false)...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
3
{ "code": "class Solution {\npublic:\n bool is_alternating_group(int alt_count, int k, int bg, int ed, const vector<bool>& alt) {\n if(alt_count==k) {\n return true;\n }\n if(alt_count==k-1 && (!alt[bg] || !alt[ed])) {\n return true;\n }\n if(alt_count==k-2 ...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
3
{ "code": "class Solution {\n public:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n const int kN = colors.size();\n colors.insert(colors.end(), colors.begin(), colors.end());\n int len = 1, last = colors[0], ret = 0;\n for (int i = 1; i < (kN << 1); ++i) {\n if (last == colors[i]) ...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
3
{ "code": "class Solution {\n public:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n const int kN = colors.size();\n colors.insert(colors.end(), colors.begin(), colors.end());\n int len = 1, last = colors[0], ret = 0;\n for (int i = 1; i < (kN << 1); ++i) {\n if (last == colors[i]) ...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
3
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n int n = colors.size();\n vector<int> doubleColors(2 * n, 0);\n\n for (int i = 0; i < n; i++) {\n doubleColors[i] = colors[i];\n doubleColors[n + i] = colors[i];\n }...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
3
{ "code": "class Solution {\npublic:\n\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n deque<int> d;\n int cur = 0;\n for (int i = 1; i < k; ++i) {\n if (colors[i] != colors[i-1]) {\n ++cur;\n d.push_back(1);\n } else {\n ...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
3
{ "code": "class Solution {\npublic:\n\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n deque<int> d;\n int cur = 0;\n for (int i = 1; i < k; ++i) {\n if (colors[i] != colors[i-1]) {\n ++cur;\n d.push_back(1);\n } else {\n ...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
3
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n stack<int> st;\n int ans = 0;\n int count = 1;\n st.push(colors[0]);\n for (int i = 1; i < colors.size(); i++) {\n if (st.top() != colors[i]) {\n st.push...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
3
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n int n=colors.size();\n stack<int> s;\n int ans=0;\n int count=1;\n s.push(colors[0]);\n for(int i=1;i<n;i++)\n {\n if(s.top()!=colors[i])\n {\n...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
3
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n int n=colors.size();\n stack<int> s;\n int ans=0;\n int count=1;\n s.push(colors[0]);\n for(int i=1;i<n;i++)\n {\n if(s.top()!=colors[i])\n {\n...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
3
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n\n int i = 0;\n int j = 1;\n int count = 0;\n deque<int> dq;\n int check = true;\n int indx = INT_MIN;\n queue<int> q;\n\n dq.push_back(colors[0]);\n dq...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
3
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n int n=colors.size();\n for(int i=0;i<n;i++)\n colors.push_back(colors[i]);\n int cnt=1;\n int ret=0;\n for(int i=1;i<n+k-1;i++){\n if(colors[i]==colors[i-1])...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
3
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n int n=colors.size();\n for(int i=0;i<n;i++)\n colors.push_back(colors[i]);\n int i=0,j=0,cnt=0,ans=0;\n \n while (j < (n+k)-1){\n if (colors[j] == colors[j+1])\n...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
3
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n int n=colors.size();\n int count=0;\n for(int i=0;i<n;i++)\n {\n colors.push_back(colors[i]);\n }\n int i=0,j=1;\n while(i<=j && j<2*n)\n {\n ...
3,483
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p> <ul> <li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li> <li><code>...
3
{ "code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n int n = colors.size();\n for(int i = 0; i < n; i++) {\n colors.push_back(colors[i]);\n }\n int islands = 1, ans = 0;\n for(int i = 1; i < n + k - 1; i++) {\n ...