(It's me, once again, same review format)
Readability
- There are way too many comments in your code. Comments should explain why you do something when it's not already clear in the code. In my opinion, the less comments some code needs, the better it is. Also, considering your comments are formatted almost exactly as your code is, it is veerryyy confusing. So, you comments only when absolutely necessary. For example : If a variable declaration needs a comment, your variable isn't well named.
max
could be renamedmaxValueInCounters
or... something like that. You get the vibe. - Your variables should have better names.
index
doesn't mean much in this context. You could rename itcounterIndex
, for example. - I'm not a big fan of this format :
if ( blablabla )
, I think the standard isif (blablabla)
. At least, you should try to be consistent in your style, because you sometimes have extra space sometimes not.
Algorithm
- When can this happen
index < N && index >= 0
? We already checked the scenario whereindex == setAllCountersOp
, so in that case theif
doesn't do anything.
Apart from that, I think your algorithm is fine.
public static int[] GetCountersAfterApplyingOperations(int N, int[] A)
{
int[] countersArr = new int[N];
int max = 0;
int index;
int setAllCountersOp = N ;
int floor = 0;
for (int i = 0; i < A.Length; i++)
{
index = A[i] - 1;
if (index == setAllCountersOp)
{
floor = max;
continue;
}
if (countersArr[index] < floor)
{
countersArr[index] = floor + 1;
}
else
{
++countersArr[index];
}
if (countersArr[index] > max)
{
++max ;
}
}
for (int i = 0; i < countersArr.Length; i ++)
{
if (countersArr[i] < floor)
{
countersArr[i] = floor;
}
}
return countersArr;
}
(It's me, once again, same review format)
Readability
- There are way too many comments in your code. Comments should explain why you do something when it's not already clear in the code. In my opinion, the less comments some code needs, the better it is. Also, considering your comments are formatted almost exactly as your code is, it is veerryyy confusing. So, you comments only when absolutely necessary. For example : If a variable declaration needs a comment, your variable isn't well named.
max
could be renamedmaxValueInCounters
or... something like that. You get the vibe. - Your variables should have better names.
index
doesn't mean much in this context. You could rename itcounterIndex
, for example. - I'm not a big fan of this format :
if ( blablabla )
, I think the standard isif (blablabla)
. At least, you should try to be consistent in your style, because you sometimes have extra space sometimes not.
Algorithm
- When can this happen
index < N && index >= 0
? We already checked the scenario whereindex == setAllCountersOp
, so in that case theif
doesn't do anything.
Apart from that, I think your algorithm is fine.
public static int[] GetCountersAfterApplyingOperations(int N, int[] A)
{
int[] countersArr = new int[N];
int max = 0;
int index;
int setAllCountersOp = N ;
int floor = 0;
for (int i = 0; i < A.Length; i++)
{
index = A[i] - 1;
if (index == setAllCountersOp)
{
floor = max;
continue;
}
if (countersArr[index] < floor)
{
countersArr[index] = floor + 1;
}
else
{
++countersArr[index];
}
if (countersArr[index] > max)
{
++max ;
}
}
for (int i = 0; i < countersArr.Length; i ++)
{
if (countersArr[i] < floor)
{
countersArr[i] = floor;
}
}
return countersArr;
}
(It's me, once again, same review format)
Readability
- There are way too many comments in your code. Comments should explain why you do something when it's not already clear in the code. In my opinion, the less comments some code needs, the better it is. Also, considering your comments are formatted almost exactly as your code is, it is veerryyy confusing. So, you comments only when absolutely necessary. For example : If a variable declaration needs a comment, your variable isn't well named.
max
could be renamedmaxValueInCounters
or... something like that. You get the vibe. - Your variables should have better names.
index
doesn't mean much in this context. You could rename itcounterIndex
, for example. - I'm not a big fan of this format :
if ( blablabla )
, I think the standard isif (blablabla)
. At least, you should try to be consistent in your style, because you sometimes have extra space sometimes not.
Algorithm
- When can this happen
index < N && index >= 0
? We already checked the scenario whereindex == setAllCountersOp
, so in that case theif
doesn't do anything.
Apart from that, I think your algorithm is fine.
public static int[] GetCountersAfterApplyingOperations(int N, int[] A)
{
int[] countersArr = new int[N];
int max = 0;
int index;
int setAllCountersOp = N ;
int floor = 0;
for (int i = 0; i < A.Length; i++)
{
index = A[i] - 1;
if (index == setAllCountersOp)
{
floor = max;
continue;
}
if (countersArr[index] < floor)
{
countersArr[index] = floor + 1;
}
else
{
++countersArr[index];
}
if (countersArr[index] > max)
{
++max ;
}
}
for (int i = 0; i < countersArr.Length; i ++)
{
if (countersArr[i] < floor)
{
countersArr[i] = floor;
}
}
return countersArr;
}
(It's me, once again, same review format)
Readability
- There are way too many comments in your code. Comments should explain why you do something when it's not already clear in the code. In my opinion, the less comments some code needs, the better it is. Also, considering your comments are formatted almost exactly as your code is, it is veerryyy confusing. So, you comments only when absolutely necessary. For example : If a variable declaration needs a comment, your variable isn't well named.
max
could be renamedmaxValueInCounters
or... something like that. You get the vibe. - Your variables should have better names.
index
doesn't mean much in this context. You could rename itcounterIndex
, for example. - I'm not a big fan of this format :
if ( blablabla )
, I think the standard isif (blablabla)
. At least, you should try to be consistent in your style, because you sometimes have extra space sometimes not.
Algorithm
- When can this happen
index < N && index >= 0
? We already checked the scenario whereindex == setAllCountersOp
, so in that case theif
doesn't do anything.
Apart from that, I think your algorithm is fine.
public static int[] GetCountersAfterApplyingOperations(int N, int[] A)
{
int[] countersArr = new int[N];
int max = 0;
int index;
int setAllCountersOp = N ;
int floor = 0;
for (int i = 0; i < A.Length; i++)
{
index = A[i] - 1;
if (index == setAllCountersOp)
{
floor = max;
continue;
}
if (countersArr[index] < floor)
{
countersArr[index] = floor + 1;
}
else
{
++countersArr[index];
}
if (countersArr[index] > max)
{
++max ;
}
}
for (int i = 0; i < countersArr.Length; i ++)
{
if (countersArr[i] < floor)
{
countersArr[i] = floor;
}
}
return countersArr;
}
(It's me, once again, same review format)
Readability
- There are way too many comments in your code. Comments should explain why you do something when it's not already clear in the code. In my opinion, the less comments some code needs, the better it is. Also, considering your comments are formatted almost exactly as your code is, it is veerryyy confusing. So, you comments only when absolutely necessary. For example : If a variable declaration needs a comment, your variable isn't well named.
max
could be renamedmaxValueInCounters
or... something like that. You get the vibe. - Your variables should have better names.
index
doesn't mean much in this context. You could rename itcounterIndex
, for example. - I'm not a big fan of this format :
if ( blablabla )
, I think the standard isif (blablabla)
. At least, you should try to be consistent in your style, because you sometimes have extra space sometimes not.
Algorithm
- When can this happen
index < N && index >= 0
? We already checked the scenario whereindex == setAllCountersOp
, so in that case theif
doesn't do anything.
Apart from that, I think your algorithm is fine.
public static int[] GetCountersAfterApplyingOperations(int N, int[] A)
{
int[] countersArr = new int[N];
int max = 0;
int index;
int setAllCountersOp = N ;
int floor = 0;
for (int i = 0; i < A.Length; i++)
{
index = A[i] - 1;
if (index == setAllCountersOp)
{
floor = max;
continue;
}
if (countersArr[index] < floor)
{
countersArr[index] = floor + 1;
}
else
{
++countersArr[index];
}
if (countersArr[index] > max)
{
++max ;
}
}
for (int i = 0; i < countersArr.Length; i ++)
{
if (countersArr[i] < floor)
{
countersArr[i] = floor;
}
}
return countersArr;
}
(It's me, once again, same review format)
Readability
- There are way too many comments in your code. Comments should explain why you do something when it's not already clear in the code. In my opinion, the less comments some code needs, the better it is. Also, considering your comments are formatted almost exactly as your code is, it is veerryyy confusing. So, you comments only when absolutely necessary. For example : If a variable declaration needs a comment, your variable isn't well named.
max
could be renamedmaxValueInCounters
or... something like that. You get the vibe. - Your variables should have better names.
index
doesn't mean much in this context. You could rename itcounterIndex
, for example. - I'm not a big fan of this format :
if ( blablabla )
, I think the standard isif (blablabla)
. At least, you should try to be consistent in your style, because you sometimes have extra space sometimes not.
Algorithm
- When can this happen
index < N && index >= 0
? We already checked the scenario whereindex == setAllCountersOp
, so in that case theif
doesn't do anything.
Apart from that, I think your algorithm is fine.
public static int[] GetCountersAfterApplyingOperations(int N, int[] A)
{
int[] countersArr = new int[N];
int max = 0;
int index;
int setAllCountersOp = N ;
int floor = 0;
for (int i = 0; i < A.Length; i++)
{
index = A[i] - 1;
if (index == setAllCountersOp)
{
floor = max;
continue;
}
if (countersArr[index] < floor)
{
countersArr[index] = floor + 1;
}
else
{
++countersArr[index];
}
if (countersArr[index] > max)
{
++max ;
}
}
for (int i = 0; i < countersArr.Length; i ++)
{
if (countersArr[i] < floor)
{
countersArr[i] = floor;
}
}
return countersArr;
}
(It's me, once again, same review format)
Readability
- There are way too many comments in your code. Comments should explain why you do something when it's not already clear in the code. In my opinion, the less comments some code needs, the better it is. Also, considering your comments are formatted almost exactly as your code is, it is veerryyy confusing. So, you comments only when absolutely necessary. For example : If a variable declaration needs a comment, your variable isn't well named.
max
could be renamedmaxValueInCounters
or... something like that. You get the vibe. - Your variables should have better names.
index
doesn't mean much in this context. You could rename itcounterIndex
, for example. - I'm not a big fan of this format :
if ( blablabla )
, I think the standard isif (blablabla)
. At least, you should try to be consistent in your style, because you sometimes have extra space sometimes not.
Algorithm
- When can this happen
index < N && index >= 0
? We already checked the scenario whereindex == setAllCountersOp
, so in that case theif
doesn't do anything.
Apart from that, I think your algorithm is fine.
public static int[] GetCountersAfterApplyingOperations(int N, int[] A)
{
int[] countersArr = new int[N];
int max = 0;
int index;
int setAllCountersOp = N ;
int floor = 0;
for ( int i = 0; i < A.Length; i++ )
{
index = A[i] - 1;
if (index == setAllCountersOp)
{
floor = max;
continue;
}
if ( countersArr[index] < floor )
{
countersArr[index] = floor + 1;
}
else
{
++countersArr[index];
}
if (countersArr[index] > max )
{
++max ;
}
}
for ( int i = 0; i < countersArr.Length; i ++ )
{
if ( countersArr[i] < floor)
{
countersArr[i] = floor;
}
}
return countersArr;
}