Skip to content

Commit

Permalink
Added codes for 25 May
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanmay-312 committed May 25, 2024
1 parent aa5e9c2 commit 47bc047
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
43 changes: 43 additions & 0 deletions GeeksForGeeks/May/25-5-24/GFG.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//{ Driver Code Starts
import java.util.*;

class GFG {
public static void main(String args[]) throws Exception {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();

while (T > 0) {
int N = sc.nextInt();
int k = sc.nextInt();
int ar[] = new int[N];
// int count = 0;
for (int i = 0; i < N; i++) ar[i] = sc.nextInt();

System.out.println(new Solution().max_Books(ar, N, k));
T--;
}
}
}
// } Driver Code Ends



class Solution {
long max_Books(int arr[], int n, int k) {
// Your code here
long curr=0;
long max=0;

for(int i=0;i<n;i++)
{
if(arr[i]<=k)
{
curr += arr[i];
max = Math.max(max,curr);
}
else
curr=0;
}
return max;
}
}
2 changes: 2 additions & 0 deletions GeeksForGeeks/May/25-5-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)
2 changes: 2 additions & 0 deletions LeetCode/May/25-5-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n! * l)
Space complexity - O(k)
30 changes: 30 additions & 0 deletions LeetCode/May/25-5-24/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class Solution
{
List<String> ans=new ArrayList<>();

public List<String> wordBreak(String s, List<String> wordDict)
{
HashSet<String> hs=new HashSet<>();
for(String str:wordDict)
hs.add(str);

findAns(0,s,hs,"");
return ans;
}

public void findAns(int index,String s,HashSet hs,String temp)
{
if(index==s.length())
{
ans.add(temp.substring(0,temp.length()-1));
return;
}

for(int i=index;i<s.length();i++)
{
String st=s.substring(index,i+1);
if(hs.contains(st))
findAns(i+1,s,hs,temp+st+" ");
}
}
}

0 comments on commit 47bc047

Please sign in to comment.