fork download
  1. class Solution {
  2. class Pair{
  3. int frequency;
  4. int number;
  5.  
  6. Pair(int frequency, int number){
  7. this.frequency=frequency;
  8. this.number=number;
  9. }
  10. }
  11. public int countStaircase(int[] nums) {
  12. int n=nums.length;
  13. int count_subarrays =0;
  14.  
  15. for(int i=0;i<n;i++){
  16. HashMap<Integer,Pair>f = new HashMap<>();
  17. int no=0;
  18. for(int j=i;j<n;j++){
  19. //my subarray is subarray[i..j]
  20.  
  21. if(!f.containsKey(nums[j])){
  22. no++;
  23. f.put(nums[j],new Pair(1,no));
  24. }
  25. else{
  26. Pair p =f.get(nums[j]);
  27. p.frequency++;
  28. }
  29.  
  30. boolean valid = true;
  31. for(Map.Entry<Integer,Pair>ii: f.entrySet()){
  32. Pair p =ii.getValue();
  33.  
  34. int freq=p.frequency;
  35. int nn =p.number;
  36.  
  37. if(freq !=nn){
  38. valid=false;
  39. break;
  40. }
  41.  
  42. }
  43.  
  44. if(valid ==true){
  45. count_subarrays++;
  46. }
  47. }
  48. }
  49.  
  50. return count_subarrays;
  51. }
  52. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:16: error: cannot find symbol
            HashMap<Integer,Pair>f = new HashMap<>();
            ^
  symbol:   class HashMap
  location: class Solution
Main.java:16: error: cannot find symbol
            HashMap<Integer,Pair>f = new HashMap<>();
                                         ^
  symbol:   class HashMap
  location: class Solution
Main.java:31: error: package Map does not exist
                for(Map.Entry<Integer,Pair>ii: f.entrySet()){
                       ^
3 errors
stdout
Standard output is empty