Note that there are some explanatory texts on larger screens.

plurals
  1. POcodility absolute distinct count from an array
    primarykey
    data
    text
    <p>so i took the codility interview test yesterday and was informed today that i failed, unfortunately i wasnt given any other information by either codility nor the employer as to where i screwed up so i would appreciate some help in knowing where i went wrong. i know codility pays alot of emphasis on how fast the program runs and how it behaves for large numbers. now i didnt copy paste the questions so this the approx of what i remember</p> <ol> <li>count the number of elements in an array a which are absolute distinct, what it means is if an array had -3 and 3 in it these numbers are not distinct because|-3|=|3|. i think an example would clear it up better</li> </ol> <p>a={-5,-3,0,1,-3} the result would be 4 because there are 4 absolute distinct elements in this array.</p> <p>The question also stated that a.length would be &lt;=10000, and most importantly it stated that assume that the <strong>array is sorted in ascending order</strong> but i didnt really understand why we would need it to be sorted</p> <p><em><strong>IF YOU THINK I MISSED SOMETHING ASK AND I WILL TRY TO CLEAR UP THE QUESTION FURTHER.</em></strong></p> <p><strong>here is my code</strong></p> <pre><code>import java.util.HashMap; import java.util.HashSet; import java.util.Set; public class test2 { int test(int[] a){ Set&lt;Integer&gt; s=new HashSet&lt;Integer&gt;(); for(int i=0;i&lt;a.length;i++){ s.add(Math.abs(a[i])); } return s.size(); } public static void main(String[] args) { test2 t=new test2(); int[] a={1,1,1,2,-1}; System.out.println(t.test(a)); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload