-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa5e9c2
commit 47bc047
Showing
4 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Time complexity - O(n) | ||
Space complexity - O(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Time complexity - O(n! * l) | ||
Space complexity - O(k) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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+" "); | ||
} | ||
} | ||
} |