Conversation
alexandru-calinoiu
left a comment
There was a problem hiding this comment.
Took a look at the problems, apprecite the fact that you've done them in kotlin, made a couple of commets take a look.
The main problem is that you did not do any unit tests to prove the functionality of any of the solutions.
| @@ -0,0 +1,11 @@ | |||
| fun main() { | |||
There was a problem hiding this comment.
The implementation is straight forward
The idea was that you get an array of n elements as an input, you don't have to generate the input.
| for(i in arr) { | ||
| if (i % 2 == 0) { | ||
| sum += arr[i] | ||
| } | ||
| } |
There was a problem hiding this comment.
There a couple of usefull functions for arrays in kotlin scout the docs maybe you can find a way to make this more idiomatic.
| for(valoare_i in arr) { | ||
| if(valoare_i > max1) { | ||
| max1 = valoare_i | ||
| }else { | ||
| max1 = max1 | ||
| } | ||
| } | ||
| for(valoare_j in arr) { | ||
| if (valoare_j > max2 && valoare_j != max1) { | ||
| max2 = valoare_j | ||
| } else { | ||
| max2 = max2 | ||
| } | ||
| } |
There was a problem hiding this comment.
Can you think of a way to do this in one loop?
Also what about some edge cases? empty array, one item array ....
| for(i in a.indices) { | ||
| if(i == 0) { | ||
| distincte += (a[i].toString() + " ") | ||
| } else if(distincte.contains(" " + a[i])) { |
There was a problem hiding this comment.
contains most likely uses a loop in it's implementation, so you are still using a loop inside a loop, there is a clear way to solve this problem.
|
Beside what @alexandru-calinoiu said, you have some naming issues that makes your code harder to read.
|
Some mentions for problem number 3: