You are viewing a single comment's thread. Return to all comments →
nice idea! not wasting memory and more importantly time in creating a list. Thanks for sharing!
When i read it correctly, she walks through 'mylist' 3 times. If she would go through each element once and do the compareision in that loop, she would walk through the list only once.
But because she also reads the input in a list and than splits it, she basicly is creating a temp list which isn't necessary. In java you can say (when using a Scanner) nextInt and don't even need a list at all.
As far as complexity goes, repeating an iteration 3 times is the same as doing it once so it's not the end of the world. Especially with the constraint that N <100.
The code idea is correct but we don't need to perform three O(n) operations for same stuff. The time complexity will remain O(n) but if taken for large array length, there will be slight difference in time in microseconds probably compared to that with one or two O(n) time complexity program.
We mostly don't care for space complexity (just for single list), thus, we may use it.
REDUCE COMPLEXITY TO WHATEVER YOU CAN!!
can you please explain this?