fork download
  1. class Solution {
  2. public int[] findThePrefixCommonArray(int[] A, int[] B) {
  3. int n = A.length;
  4. HashMap<Integer,Integer>f =new HashMap<>();
  5.  
  6. int[] C=new int[n];
  7. int count=0;
  8.  
  9. for(int i=0;i<n;i++){
  10. if(A[i]==B[i]){
  11. count++;
  12. }
  13. else{
  14. if(f.containsKey(A[i])){
  15. count+=f.getOrDefault(A[i],0);
  16. }
  17. if(f.containsKey(B[i])){
  18. count+=f.getOrDefault(B[i],0);
  19.  
  20. }
  21. }
  22. C[i]=count;
  23. f.put(A[i],f.getOrDefault(A[i],0)+1);
  24. f.put(B[i],f.getOrDefault(B[i],0)+1);
  25.  
  26. }
  27. return C;
  28. }
  29. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:4: error: cannot find symbol
        HashMap<Integer,Integer>f =new HashMap<>();
        ^
  symbol:   class HashMap
  location: class Solution
Main.java:4: error: cannot find symbol
        HashMap<Integer,Integer>f =new HashMap<>();
                                       ^
  symbol:   class HashMap
  location: class Solution
2 errors
stdout
Standard output is empty