Problem Link
Solution Link
Algorithm : Brute Force
Explanation:
It is a programming problem for beginners. The problem is about array manipulation. I have used a nested for loop to compare every possible pair. If they have the same value they are assigned -1 and the count is incremented. Here of course, you need to check whether any element is -1 before comparing for equality, otherwise, if both are -1, the count variable will be incremented.
Runtime : O(n^2) (due to the second order nested for loop)
Required Space : O(n) (Using one dimension array)
NOTE: I will try to post a more efficient solution with less run-time in near future.
No comments:
Post a Comment