diff --git a/1014. Best Sightseeing Pair b/1014. Best Sightseeing Pair new file mode 100644 index 0000000..bc90bac --- /dev/null +++ b/1014. Best Sightseeing Pair @@ -0,0 +1,11 @@ +class Solution { + public int maxScoreSightseeingPair(int[] values) { + int result =0; + int max = values[0]; + for(int i=1;i a[0]==b[0]?a[1]-b[1]:a[0]-b[0]); + + return helper(events,0,k,n); //o(N*K) * O(logN) + } + + int helper(int[][] events,int pos,int k,int n){ + if(pos>=n || k==0){ + return 0; + } + + if(dp[pos][k]>-1){ + return dp[pos][k]; + } + + int nextPos = nextEvent(events,pos,n); // O(logN) + int select = events[pos][2] + helper(events,nextPos,k-1,n); + int reject = helper(events,pos+1,k,n); + dp[pos][k]= Math.max(select,reject); + return dp[pos][k]; + } + + int nextEvent(int[][] events,int pos, int n){ + int endDay = events[pos][1]; + pos++; + while(posendDay){ + n =mid; + } + else{ + pos = mid+1; + } + } + return n; + } +} diff --git a/2116. Check if a Parentheses String Can Be Valid b/2116. Check if a Parentheses String Can Be Valid new file mode 100644 index 0000000..4875d5f --- /dev/null +++ b/2116. Check if a Parentheses String Can Be Valid @@ -0,0 +1,36 @@ +class Solution { + public boolean canBeValid(String s, String locked) { + if(s.length()%2!=0) return false; + Stack unlocked = new Stack<>(); + Stack open = new Stack<>(); + char[] stArray = s.toCharArray(); + char[] lArray = locked.toCharArray(); + + for(int i=0;i0){ + open.pop(); + } + else if(unlocked.size()>0){ + unlocked.pop(); + } + else{ + return false; + } + } + } + + while(open.size()>0 && unlocked.size()>0 && open.peek() freq = new HashMap<>(); + + while(end < nums.length) { + int currentFreq = freq.getOrDefault(nums[end], 0); + + if(currentFreq < k) { + freq.put(nums[end], currentFreq+1); + } + else { + while(nums[start] != nums[end]) { + freq.put(nums[start], freq.get(nums[start])-1); + start++; + } + start++; + } + + int newWindowLength = end-start+1; + result = Math.max(result, newWindowLength); + + end++; + + } + + return result; + } +} diff --git a/3223. Minimum Length of String After Operations b/3223. Minimum Length of String After Operations new file mode 100644 index 0000000..506570d --- /dev/null +++ b/3223. Minimum Length of String After Operations @@ -0,0 +1,14 @@ +class Solution { + public int minimumLength(String s) { + char[] ch = s.toCharArray(); + int[] count = new int[26]; + for(char c:ch){ + count[c-'a']++; + } + int result = 0; + for(int ct: count){ + if(ct>0) result+=(ct%2==0?2:1); + } + return result; + } +} diff --git a/724. Find Pivot Index b/724. Find Pivot Index new file mode 100644 index 0000000..c0bd1e9 --- /dev/null +++ b/724. Find Pivot Index @@ -0,0 +1,17 @@ +class Solution { + public int pivotIndex(int[] nums) { + int total=0; + for(int num:nums){ + total+=num; + } + + int leftSum=0; + for(int i=0;i