Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Java/.project
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
</natures>
<filteredResources>
<filter>

<id>1744612223460</id>

<name></name>
<type>30</type>
<matcher>
Expand Down
26 changes: 26 additions & 0 deletions Java/Count Largest Group.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Solution {
public int countLargestGroup(int n) {
Map<Integer, Integer>hashMap=new HashMap<Integer,Integer>();
int maxValue=0;
for(int i=1;i<=n;i++)
{
int key=0,num=i;
while(num!=0)
{
key+=num%10;
num=num/10;
}
hashMap.put(key,hashMap.getOrDefault(key,0)+1);
maxValue=Math.max(maxValue,hashMap.get(key));
}
int count=0;
for(Map.Entry<Integer,Integer>kvpair: hashMap.entrySet()){
if(kvpair.getValue()== maxValue)
{
++count;
}
}
return count;

}
}
28 changes: 28 additions & 0 deletions Java/Count of Subarrays in An Array.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Solution {
public int countCompleteSubarrays(int[] nums) {
int cnt = 0;
HashSet<Integer> set = new HashSet<>();
for (int i = 0; i < nums.length; i++) {
set.add(nums[i]);
}
HashMap<Integer, Integer> map = new HashMap<>();
int i = 0, j = 0;
while (j < nums.length) {
map.put(nums[j], map.getOrDefault(nums[j], 0) + 1);
if (map.size() == set.size()) {
cnt += nums.length - j;
while (true) {
map.put(nums[i], map.get(nums[i]) - 1);
if (map.get(nums[i]) == 0) {
map.remove(nums[i++]);
break;
}
cnt += nums.length - j;
i++;
}
}
j++;
}
return cnt;
}
}