Skip to content
Open
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
49 changes: 49 additions & 0 deletions BiWeekly89/A.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//https://leetcode.com/contest/biweekly-contest-89/problems/number-of-valid-clock-times/

class Solution {

int ans;
public int countTime(String s) {

char[] ch = new char[]{s.charAt(0),s.charAt(1),s.charAt(3),s.charAt(4)};

ans = 0;

sol(0,ch,false);

return (ans == 0) ? 1 : ans;
}

void sol(int idx,char[] ch,boolean flag) {

if(idx == ch.length) {

String s = new String(ch);
String st = s.substring(2);

if(flag) {

if(s.compareTo("24") < 0 && st.compareTo("60") < 0) ans++;
}

return;
}

char t = ch[idx];

if(t == '?') {

for(char i = '0' ; i <= '9' ; i++) {

ch[idx] = i;
sol(idx+1,ch,true);
}

ch[idx] = '?';
}
else{

sol(idx+1,ch,flag);
}
}
}
34 changes: 34 additions & 0 deletions BiWeekly89/B.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//https://leetcode.com/contest/biweekly-contest-89/problems/range-product-queries-of-powers/

import java.util.*;

class Solution {
public int[] productQueries(int n, int[][] q) {

List<Integer> l = new ArrayList<>();

for(int i=0;i<31;i++) {

int mask = 1 << i;

if((mask & n) > 0) {

l.add(1 << i);
}
}

int[] ans = new int[q.length];
int i = 0;

for(int[] a : q) {

long p = 1 ;

for(int j=a[0];j<=a[1];j++) p = (p * l.get(j)) % (1000000000 + 7);

ans[i++] = (int)p;
}

return ans;
}
}
51 changes: 51 additions & 0 deletions BiWeekly89/C.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//https://leetcode.com/contest/biweekly-contest-89/problems/minimize-maximum-of-array/

class Solution {
public int minimizeArrayValue(int[] nums) {

int max = nums[0];

for(int ele : nums) max = Math.max(max,ele);

int l = 0 , h = max;
int ans = h;

while(l <= h) {

int mid = l + (h - l) / 2;

if(isP(nums,mid)) {

ans = mid;
h = mid - 1;
}
else{

l = mid+1;
}
}

return ans;
}

boolean isP(int[] a,int val) {

long s = 0;

for(int ele : a) {

if(ele < val) {

s += val - ele;
}
else if(ele > val) {

s -= ele - val;
}

if(s < 0) return false;
}

return true;
}
}