-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay_60.java
More file actions
42 lines (40 loc) · 1 KB
/
Copy pathDay_60.java
File metadata and controls
42 lines (40 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Frequency of the Most Frequent Element
class Solution {
public int maxFrequency(int[] nums, int k) {
int n = nums.length;
Arrays.sort(nums);
int cnt = 0, l = 0;
long sum = 0;
for(int r=0;r<n;r++){
sum+=nums[r];
while((long)(nums[r]) * (r-l+1) > sum + k){
sum-=nums[l];
l++;
}
cnt = Math.max(cnt,r-l+1);
}
return cnt;
}
}
// Smallest Missing Integer Greater Than Sequential Prefix Sum
class Solution {
public int missingInteger(int[] nums) {
int n = nums.length;
int sum = nums[0];
for(int i=1;i<n;i++){
if(nums[i] - 1 == nums[i-1]){
sum+=nums[i];
}
else break;
}
Set<Integer> st = new HashSet<>();
for(int it : nums){
st.add(it);
}
while(true){
if(st.contains(sum)) sum++;
else break;
}
return sum;
}
}