Skip to content

Commit

Permalink
Added codes for 7 April
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanmay-312 committed Apr 7, 2024
1 parent 0a216c2 commit bf613b6
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
49 changes: 49 additions & 0 deletions GeeksForGeeks/April/07-4-24/GFG.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//{ Driver Code Starts
//Initial Template for Java

import java.io.*;
import java.util.*;
class GfG
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0)
{
int n = sc.nextInt();
int m = sc.nextInt();
int a[] = new int[n];
int b[] = new int[m];
for(int i = 0;i<n;i++)
a[i] = sc.nextInt();
for(int i = 0;i<m;i++)
b[i] = sc.nextInt();
Solution ob = new Solution();
System.out.println(ob.maxDotProduct(n, m, a, b));
}
}
}
// } Driver Code Ends


//User function Template for Java

class Solution
{
public int maxDotProduct(int n, int m, int a[], int b[])
{
// Your code goes here
int[][] dp = new int[m + 1][n + 1];

for (int i = 1; i <= m; i++)
{
for (int j = i; j <= n; j++)
{
dp[i][j] = Math.max(dp[i - 1][j - 1] + a[j - 1] * b[i - 1], dp[i][j - 1]);
}
}

return dp[m][n];
}
}
2 changes: 2 additions & 0 deletions GeeksForGeeks/April/07-4-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n*m)
Space complexity - O(n*m)
2 changes: 2 additions & 0 deletions LeetCode/April/07-4-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n)
Space complexity - O(1)
32 changes: 32 additions & 0 deletions LeetCode/April/07-4-24/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class Solution
{
public boolean checkValidString(String s)
{
int low = 0;
int high = 0;

for (char c : s.toCharArray())
{
switch (c)
{
case '(':
++low;
++high;
break;
case ')':
low = Math.max(0, --low);
--high;
break;
case '*':
low = Math.max(0, --low);
++high;
break;
}

if (high < 0)
return false;
}

return low == 0;
}
}

0 comments on commit bf613b6

Please sign in to comment.